From: <sv...@va...> - 2012-06-07 09:23:40
|
sewardj 2012-06-07 10:23:23 +0100 (Thu, 07 Jun 2012) New Revision: 12617 Log: Merge in a port for mips32-linux, by Petar Jovanovic and Dejan Jevtic, mip...@rt..., Bug 270777. Valgrind: new non-test files for mips32-linux. Added files: trunk/cachegrind/cg-mips32.c trunk/coregrind/m_dispatch/dispatch-mips32-linux.S trunk/coregrind/m_gdbserver/mips-cp0-valgrind-s1.xml trunk/coregrind/m_gdbserver/mips-cp0-valgrind-s2.xml trunk/coregrind/m_gdbserver/mips-cp0.xml trunk/coregrind/m_gdbserver/mips-cpu-valgrind-s1.xml trunk/coregrind/m_gdbserver/mips-cpu-valgrind-s2.xml trunk/coregrind/m_gdbserver/mips-cpu.xml trunk/coregrind/m_gdbserver/mips-fpu-valgrind-s1.xml trunk/coregrind/m_gdbserver/mips-fpu-valgrind-s2.xml trunk/coregrind/m_gdbserver/mips-fpu.xml trunk/coregrind/m_gdbserver/mips-linux-valgrind.xml trunk/coregrind/m_gdbserver/mips-linux.xml trunk/coregrind/m_gdbserver/valgrind-low-mips32.c trunk/coregrind/m_sigframe/sigframe-mips32-linux.c trunk/coregrind/m_syswrap/syscall-mips32-linux.S trunk/coregrind/m_syswrap/syswrap-mips32-linux.c trunk/include/vki/vki-mips32-linux.h trunk/include/vki/vki-posixtypes-mips32-linux.h trunk/include/vki/vki-scnums-mips32-linux.h Added: trunk/coregrind/m_gdbserver/mips-cp0.xml (+13 -0) =================================================================== --- trunk/coregrind/m_gdbserver/mips-cp0.xml 2012-06-07 10:13:21 +01:00 (rev 12616) +++ trunk/coregrind/m_gdbserver/mips-cp0.xml 2012-06-07 10:23:23 +01:00 (rev 12617) @@ -0,0 +1,13 @@ +<?xml version="1.0"?> +<!-- Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. + + Copying and distribution of this file, with or without modification, + are permitted in any medium without royalty provided the copyright + notice and this notice are preserved. --> + +<!DOCTYPE feature SYSTEM "gdb-target.dtd"> +<feature name="org.gnu.gdb.mips.cp0"> + <reg name="status" bitsize="32" regnum="32"/> + <reg name="badvaddr" bitsize="32" regnum="35"/> + <reg name="cause" bitsize="32" regnum="36"/> +</feature> Added: trunk/coregrind/m_sigframe/sigframe-mips32-linux.c (+398 -0) =================================================================== --- trunk/coregrind/m_sigframe/sigframe-mips32-linux.c 2012-06-07 10:13:21 +01:00 (rev 12616) +++ trunk/coregrind/m_sigframe/sigframe-mips32-linux.c 2012-06-07 10:23:23 +01:00 (rev 12617) @@ -0,0 +1,398 @@ + +/*--------------------------------------------------------------------*/ +/*--- Create/destroy signal delivery frames. ---*/ +/*--- sigframe-mips32-linux.c ---*/ +/*--------------------------------------------------------------------*/ + +/* + This file is part of Valgrind, a dynamic binary instrumentation + framework. + + Copyright (C) 2010-2012 RT-RK + mip...@rt... + + 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. +*/ + +#if defined(VGP_mips32_linux) + +#include "pub_core_basics.h" +#include "pub_core_vki.h" +#include "pub_core_vkiscnums.h" +#include "pub_core_libcsetjmp.h" // to keep _threadstate.h happy +#include "pub_core_threadstate.h" +#include "pub_core_aspacemgr.h" +#include "pub_core_libcbase.h" +#include "pub_core_libcassert.h" +#include "pub_core_libcprint.h" +#include "pub_core_machine.h" +#include "pub_core_options.h" +#include "pub_core_sigframe.h" +#include "pub_core_signals.h" +#include "pub_core_tooliface.h" +#include "pub_core_trampoline.h" +#include "pub_core_transtab.h" // VG_(discard_translations) + +struct vg_sig_private +{ + UInt magicPI; + UInt sigNo_private; + VexGuestMIPS32State vex_shadow1; + VexGuestMIPS32State vex_shadow2; +}; + +struct sigframe +{ + UInt sf_ass[4]; /* argument save space for o32 */ + UInt sf_pad[2]; /* Was: signal trampoline */ + struct vki_sigcontext sf_sc; + vki_sigset_t sf_mask; + struct vg_sig_private priv; +}; + +struct rt_sigframe +{ + UInt rs_ass[4]; /* argument save space for o32 */ + UInt rs_pad[2]; /* Was: signal trampoline */ + vki_siginfo_t rs_info; + struct vki_ucontext rs_uc; + struct vg_sig_private priv; +}; + +/* Extend the stack segment downwards if needed so as to ensure the + new signal frames are mapped to something. Return a Bool + indicating whether or not the operation was successful. +*/ +static Bool extend ( ThreadState *tst, Addr addr, SizeT size ) +{ + ThreadId tid = tst->tid; + NSegment const* stackseg = NULL; + + if (VG_(extend_stack)(addr, tst->client_stack_szB)) + { + stackseg = VG_(am_find_nsegment)(addr); + } + + if (stackseg == NULL || !stackseg->hasR || !stackseg->hasW) + { + VG_(message)(Vg_UserMsg, + "Can't extend stack to %#lx during signal delivery for thread %d:\n", + addr, tid ); + if (stackseg == NULL) + VG_(message)( Vg_UserMsg, " no stack segment\n" ); + else + VG_(message)( Vg_UserMsg, " too small or bad protection modes\n" ); + + /* set SIGSEGV to default handler */ + VG_(set_default_handler)( VKI_SIGSEGV ); + VG_(synth_fault_mapping)( tid, addr ); + + /* The whole process should be about to die, since the default + action of SIGSEGV to kill the whole process. */ + return False; + } + + /* For tracking memory events, indicate the entire frame has been + allocated. */ + VG_TRACK( new_mem_stack_signal, addr - VG_STACK_REDZONE_SZB, + size + VG_STACK_REDZONE_SZB, tid ); + + return True; +} + +static +void setup_sigcontext2 ( ThreadState* tst, struct vki_sigcontext **sc1, const vki_siginfo_t *si) +{ + + struct vki_sigcontext *sc = *sc1; + + VG_TRACK( pre_mem_write, Vg_CoreSignal, tst->tid, "signal frame mcontext", + (Addr)sc, sizeof(unsigned long long)*34 ); + sc->sc_regs[1] = tst->arch.vex.guest_r1; + sc->sc_regs[2] = tst->arch.vex.guest_r2; + sc->sc_regs[3] = tst->arch.vex.guest_r3; + sc->sc_regs[4] = tst->arch.vex.guest_r4; + sc->sc_regs[5] = tst->arch.vex.guest_r5; + sc->sc_regs[6] = tst->arch.vex.guest_r6; + sc->sc_regs[7] = tst->arch.vex.guest_r7; + sc->sc_regs[8] = tst->arch.vex.guest_r8; + sc->sc_regs[9] = tst->arch.vex.guest_r9; + sc->sc_regs[10] = tst->arch.vex.guest_r10; + sc->sc_regs[11] = tst->arch.vex.guest_r11; + sc->sc_regs[12] = tst->arch.vex.guest_r12; + sc->sc_regs[13] = tst->arch.vex.guest_r13; + sc->sc_regs[14] = tst->arch.vex.guest_r14; + sc->sc_regs[15] = tst->arch.vex.guest_r15; + sc->sc_regs[16] = tst->arch.vex.guest_r16; + sc->sc_regs[17] = tst->arch.vex.guest_r17; + sc->sc_regs[18] = tst->arch.vex.guest_r18; + sc->sc_regs[19] = tst->arch.vex.guest_r19; + sc->sc_regs[20] = tst->arch.vex.guest_r20; + sc->sc_regs[21] = tst->arch.vex.guest_r21; + sc->sc_regs[22] = tst->arch.vex.guest_r22; + sc->sc_regs[23] = tst->arch.vex.guest_r23; + sc->sc_regs[24] = tst->arch.vex.guest_r24; + sc->sc_regs[25] = tst->arch.vex.guest_r25; + sc->sc_regs[26] = tst->arch.vex.guest_r26; + sc->sc_regs[27] = tst->arch.vex.guest_r27; + sc->sc_regs[28] = tst->arch.vex.guest_r28; + sc->sc_regs[29] = tst->arch.vex.guest_r29; + sc->sc_regs[30] = tst->arch.vex.guest_r30; + sc->sc_regs[31] = tst->arch.vex.guest_r31; + sc->sc_pc = tst->arch.vex.guest_PC; + sc->sc_mdhi = tst->arch.vex.guest_HI; + sc->sc_mdlo = tst->arch.vex.guest_LO; +} + +/* EXPORTED */ +void VG_(sigframe_create)( ThreadId tid, + Addr sp_top_of_frame, + const vki_siginfo_t *siginfo, + const struct vki_ucontext *siguc, + void *handler, + UInt flags, + const vki_sigset_t *mask, + void *restorer ) +{ + Addr sp; + ThreadState* tst = VG_(get_ThreadState)(tid); + Addr faultaddr; + Int sigNo = siginfo->si_signo; + struct vg_sig_private *priv; + + /* Stack must be 8-byte aligned */ + sp_top_of_frame &= ~0xf; + + if (flags & VKI_SA_SIGINFO) + { + sp = sp_top_of_frame - sizeof(struct rt_sigframe); + } + else + { + sp = sp_top_of_frame - sizeof(struct sigframe); + } + + tst = VG_(get_ThreadState)(tid); + if (!extend(tst, sp, sp_top_of_frame - sp)) + return; + + vg_assert(VG_IS_8_ALIGNED(sp)); + + /* SIGILL defines addr to be the faulting address */ + + faultaddr = (Addr)siginfo->_sifields._sigfault._addr; + if (sigNo == VKI_SIGILL && siginfo->si_code > 0) + faultaddr = tst->arch.vex.guest_PC; + + if (flags & VKI_SA_SIGINFO) + { + struct rt_sigframe *frame = (struct rt_sigframe *) sp; + struct vki_ucontext *ucp = &frame->rs_uc; + if (VG_(clo_trace_signals)) + VG_(printf)("rt_sigframe\n"); + /* Create siginfo. */ + VG_TRACK( pre_mem_write, Vg_CoreSignal, tid, "signal frame siginfo", + (Addr)&frame->rs_info, sizeof(frame->rs_info) ); + + VG_(memcpy)(&frame->rs_info, siginfo, sizeof(*siginfo)); + + VG_TRACK( post_mem_write, Vg_CoreSignal, tid, + (Addr)&frame->rs_info, sizeof(frame->rs_info) ); + + /* Create the ucontext. */ + VG_TRACK( pre_mem_write, Vg_CoreSignal, tid, "signal frame ucontext", + (Addr)ucp, offsetof(struct vki_ucontext, uc_mcontext) ); + + ucp->uc_flags = 0; + ucp->uc_link = 0; + ucp->uc_stack = tst->altstack; + + VG_TRACK( post_mem_write, Vg_CoreSignal, tid, (Addr)ucp, + offsetof(struct vki_ucontext, uc_mcontext) ); + + struct vki_sigcontext *scp = &(frame->rs_uc.uc_mcontext); + setup_sigcontext2(tst, &(scp), siginfo); + + ucp->uc_sigmask = tst->sig_mask; + + priv = &frame->priv; + + /* + * Arguments to signal handler: + * + * a0 = signal number + * a1 = 0 (should be cause) + * a2 = pointer to ucontext + * + * $25 and c0_epc point to the signal handler, $29 points to + * the struct rt_sigframe. + */ + + tst->arch.vex.guest_r4 = siginfo->si_signo; + tst->arch.vex.guest_r5 = (Addr) &frame->rs_info; + tst->arch.vex.guest_r6 = (Addr) &frame->rs_uc; + tst->arch.vex.guest_r29 = (Addr) frame; + tst->arch.vex.guest_r25 = (Addr) handler; + + if (flags & VKI_SA_RESTORER) + { + tst->arch.vex.guest_r31 = (Addr) restorer; + } + else + { + tst->arch.vex.guest_r31 = (Addr)&VG_(mips32_linux_SUBST_FOR_rt_sigreturn); + } + + } + else + { + if (VG_(clo_trace_signals)) + VG_(printf)("sigframe\n"); + struct sigframe *frame = (struct sigframe *) sp; + struct vki_sigcontext *scp = &(frame->sf_sc); + setup_sigcontext2(tst, &(scp), siginfo); + frame->sf_mask = tst->sig_mask; + priv = &frame->priv; + /* + * Arguments to signal handler: + * + * a0 = signal number + * a1 = 0 (should be cause) + * a2 = pointer to struct sigcontext + * + * $25 and c0_epc point to the signal handler, $29 points to the + * struct sigframe. + */ + tst->arch.vex.guest_r4 = siginfo->si_signo; + tst->arch.vex.guest_r5 = 0; + tst->arch.vex.guest_r6 = (Addr) &frame->sf_sc; + tst->arch.vex.guest_r29 = (Addr) frame; + tst->arch.vex.guest_r25 = (Addr) handler; + + if (flags & VKI_SA_RESTORER) + { + tst->arch.vex.guest_r31 = (Addr) restorer; + } + else + { + tst->arch.vex.guest_r31 = (Addr)&VG_(mips32_linux_SUBST_FOR_sigreturn); + } + } + + priv->magicPI = 0x31415927; + priv->sigNo_private = sigNo; + priv->vex_shadow1 = tst->arch.vex_shadow1; + priv->vex_shadow2 = tst->arch.vex_shadow2; + /* Set the thread so it will next run the handler. */ + /* tst->m_sp = sp; also notify the tool we've updated SP */ + VG_TRACK( post_reg_write, Vg_CoreSignal, tid, VG_O_STACK_PTR, sizeof(Addr)); + if (VG_(clo_trace_signals)) + VG_(printf)("handler = %p\n", handler); + tst->arch.vex.guest_PC = (Addr) handler; + /* This thread needs to be marked runnable, but we leave that the + caller to do. */ +} + +/* EXPORTED */ +void VG_(sigframe_destroy)( ThreadId tid, Bool isRT ) +{ + ThreadState *tst; + struct vg_sig_private *priv1; + Addr sp; + UInt frame_size; + struct vki_sigcontext *mc; + Int sigNo; + Bool has_siginfo = isRT; + + vg_assert(VG_(is_valid_tid)(tid)); + tst = VG_(get_ThreadState)(tid); + sp = tst->arch.vex.guest_r29; + if (has_siginfo) + { + struct rt_sigframe *frame = (struct rt_sigframe *)sp; + struct vki_ucontext *ucp = &frame->rs_uc; + frame_size = sizeof(*frame); + mc = &ucp->uc_mcontext; + priv1 = &frame->priv; + vg_assert(priv1->magicPI == 0x31415927); + sigNo = priv1->sigNo_private; + } + else + { + struct sigframe *frame = (struct sigframe *)sp; + frame_size = sizeof(*frame); + mc = &(frame->sf_sc); + priv1 = &frame->priv; + vg_assert(priv1->magicPI == 0x31415927); + tst->sig_mask = frame->sf_mask; + tst->tmp_sig_mask = tst->sig_mask; + sigNo = priv1->sigNo_private; + } + //restore regs + tst->arch.vex.guest_r1 = mc->sc_regs[1]; + tst->arch.vex.guest_r2 = mc->sc_regs[2]; + tst->arch.vex.guest_r3 = mc->sc_regs[3]; + tst->arch.vex.guest_r4 = mc->sc_regs[4]; + tst->arch.vex.guest_r5 = mc->sc_regs[5]; + tst->arch.vex.guest_r6 = mc->sc_regs[6]; + tst->arch.vex.guest_r7 = mc->sc_regs[7]; + tst->arch.vex.guest_r8 = mc->sc_regs[8]; + tst->arch.vex.guest_r9 = mc->sc_regs[9]; + tst->arch.vex.guest_r10 = mc->sc_regs[10]; + tst->arch.vex.guest_r11 = mc->sc_regs[11]; + tst->arch.vex.guest_r12 = mc->sc_regs[12]; + tst->arch.vex.guest_r13= mc->sc_regs[13]; + tst->arch.vex.guest_r14 = mc->sc_regs[14]; + tst->arch.vex.guest_r15 = mc->sc_regs[15]; + tst->arch.vex.guest_r16 = mc->sc_regs[16]; + tst->arch.vex.guest_r17 = mc->sc_regs[17]; + tst->arch.vex.guest_r18 = mc->sc_regs[18]; + tst->arch.vex.guest_r19 = mc->sc_regs[19]; + tst->arch.vex.guest_r20 = mc->sc_regs[20]; + tst->arch.vex.guest_r21 = mc->sc_regs[21]; + tst->arch.vex.guest_r22 = mc->sc_regs[22]; + tst->arch.vex.guest_r23 = mc->sc_regs[23]; + tst->arch.vex.guest_r24 = mc->sc_regs[24]; + tst->arch.vex.guest_r25 = mc->sc_regs[25]; + tst->arch.vex.guest_r26 = mc->sc_regs[26]; + tst->arch.vex.guest_r27 = mc->sc_regs[27]; + tst->arch.vex.guest_r28 = mc->sc_regs[28]; + tst->arch.vex.guest_r30 = mc->sc_regs[30]; + tst->arch.vex.guest_PC = mc->sc_pc; + tst->arch.vex.guest_r31 = mc->sc_regs[31]; + tst->arch.vex.guest_r29 = mc->sc_regs[29]; + + tst->arch.vex.guest_HI = mc->sc_mdhi; + tst->arch.vex.guest_LO = mc->sc_mdlo; + tst->arch.vex_shadow1 = priv1->vex_shadow1; + tst->arch.vex_shadow2 = priv1->vex_shadow2; + + VG_TRACK(die_mem_stack_signal, sp, frame_size); + if (VG_(clo_trace_signals)) + VG_(message)( Vg_DebugMsg, + "VG_(signal_return) (thread %d): isRT=%d valid magic; EIP=%#x\n", + tid, isRT, tst->arch.vex.guest_PC); + /* tell the tools */ + VG_TRACK( post_deliver_signal, tid, sigNo ); +} + +#endif // defined(VGP_mips32_linux) + +/*--------------------------------------------------------------------*/ +/*--- end sigframe-mips32-linux.c ---*/ +/*--------------------------------------------------------------------*/ Added: trunk/coregrind/m_gdbserver/mips-cpu.xml (+46 -0) =================================================================== --- trunk/coregrind/m_gdbserver/mips-cpu.xml 2012-06-07 10:13:21 +01:00 (rev 12616) +++ trunk/coregrind/m_gdbserver/mips-cpu.xml 2012-06-07 10:23:23 +01:00 (rev 12617) @@ -0,0 +1,46 @@ +<?xml version="1.0"?> +<!-- Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. + + Copying and distribution of this file, with or without modification, + are permitted in any medium without royalty provided the copyright + notice and this notice are preserved. --> + +<!DOCTYPE feature SYSTEM "gdb-target.dtd"> +<feature name="org.gnu.gdb.mips.cpu"> + <reg name="r0" bitsize="32" regnum="0"/> + <reg name="r1" bitsize="32"/> + <reg name="r2" bitsize="32"/> + <reg name="r3" bitsize="32"/> + <reg name="r4" bitsize="32"/> + <reg name="r5" bitsize="32"/> + <reg name="r6" bitsize="32"/> + <reg name="r7" bitsize="32"/> + <reg name="r8" bitsize="32"/> + <reg name="r9" bitsize="32"/> + <reg name="r10" bitsize="32"/> + <reg name="r11" bitsize="32"/> + <reg name="r12" bitsize="32"/> + <reg name="r13" bitsize="32"/> + <reg name="r14" bitsize="32"/> + <reg name="r15" bitsize="32"/> + <reg name="r16" bitsize="32"/> + <reg name="r17" bitsize="32"/> + <reg name="r18" bitsize="32"/> + <reg name="r19" bitsize="32"/> + <reg name="r20" bitsize="32"/> + <reg name="r21" bitsize="32"/> + <reg name="r22" bitsize="32"/> + <reg name="r23" bitsize="32"/> + <reg name="r24" bitsize="32"/> + <reg name="r25" bitsize="32"/> + <reg name="r26" bitsize="32"/> + <reg name="r27" bitsize="32"/> + <reg name="r28" bitsize="32"/> + <reg name="r29" bitsize="32"/> + <reg name="r30" bitsize="32"/> + <reg name="r31" bitsize="32"/> + + <reg name="lo" bitsize="32" regnum="33"/> + <reg name="hi" bitsize="32" regnum="34"/> + <reg name="pc" bitsize="32" regnum="37"/> +</feature> Added: trunk/include/vki/vki-posixtypes-mips32-linux.h (+68 -0) =================================================================== --- trunk/include/vki/vki-posixtypes-mips32-linux.h 2012-06-07 10:13:21 +01:00 (rev 12616) +++ trunk/include/vki/vki-posixtypes-mips32-linux.h 2012-06-07 10:23:23 +01:00 (rev 12617) @@ -0,0 +1,68 @@ + +/*--------------------------------------------------------------------*/ +/*--- mips/Linux-specific kernel interface: posix types. ---*/ +/*--- vki-posixtypes-mips32-linux.h ---*/ +/*--------------------------------------------------------------------*/ + +/* + This file is part of Valgrind, a dynamic binary instrumentation + framework. + + Copyright (C) 2010-2012 RT-RK + mip...@rt... + + 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_MIPS32_LINUX_H +#define __VKI_POSIXTYPES_MIPS32_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_MIPS32_LINUX_H + +/*--------------------------------------------------------------------*/ +/*--- end vki-posixtypes-mips32-linux.h ---*/ +/*--------------------------------------------------------------------*/ Added: trunk/include/vki/vki-mips32-linux.h (+973 -0) =================================================================== --- trunk/include/vki/vki-mips32-linux.h 2012-06-07 10:13:21 +01:00 (rev 12616) +++ trunk/include/vki/vki-mips32-linux.h 2012-06-07 10:23:23 +01:00 (rev 12617) @@ -0,0 +1,973 @@ + +/*--------------------------------------------------------------------*/ +/*--- mips/Linux-specific kernel interface. vki-mips32-linux.h ---*/ +/*--------------------------------------------------------------------*/ + +/* + This file is part of Valgrind, a dynamic binary instrumentation + framework. + + Copyright (C) 2010-2012 RT-RK + mip...@rt... + + 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_MIPS32_LINUX_H +#define __VKI_MIPS32_LINUX_H + +#include <config.h> + +// mips endian +#if defined (_MIPSEL) +#define VKI_LITTLE_ENDIAN 1 +#elif defined (_MIPSEB) +#define VKI_BIG_ENDIAN 1 +#endif + + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-generic/int-ll64.h +//---------------------------------------------------------------------- + +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 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; + + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/page.h +//---------------------------------------------------------------------- + +/* PAGE_SHIFT determines the page size */ +#define VKI_PAGE_SHIFT MIPS_PAGE_SHIFT +#define VKI_PAGE_SIZE (1UL << VKI_PAGE_SHIFT) +#define VKI_PAGE_MASK (~(VKI_PAGE_SIZE-1)) +#define VKI_MAX_PAGE_SHIFT VKI_PAGE_SHIFT +#define VKI_MAX_PAGE_SIZE VKI_PAGE_SIZE + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/arch/mips/include/asm-generic/shmparam.h +//---------------------------------------------------------------------- + +#define VKI_SHMLBA SHM_ALIGNMENT + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm/signal.h +//---------------------------------------------------------------------- + +#define VKI_MINSIGSTKSZ 2048 + +#define VKI_SIG_BLOCK 1 /* for blocking signals */ +#define VKI_SIG_UNBLOCK 2 /* for unblocking signals */ +#define VKI_SIG_SETMASK 3 /* for setting the signal mask */ + +/* Type of a signal handler. */ +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; + +/* Fake signal functions */ +#define VKI_SIG_DFL ((__vki_signalfn_t)0) /* default signal handling */ +#define VKI_SIG_IGN ((__vki_signalfn_t)1) /* ignore signal */ +#define VKI_SIG_ERR ((__vki_signalfn_t)-1) /* error return from signal */ + +#define _VKI_NSIG 128 +#define _VKI_NSIG_BPW 32 +#define _VKI_NSIG_WORDS (_VKI_NSIG / _VKI_NSIG_BPW) + +typedef unsigned long vki_old_sigset_t; /* at least 32 bits */ + +typedef struct { + unsigned long sig[_VKI_NSIG_WORDS]; +} vki_sigset_t; + +#define VKI_SIGHUP 1 /* Hangup (POSIX). */ +#define VKI_SIGINT 2 /* Interrupt (ANSI). */ +#define VKI_SIGQUIT 3 /* Quit (POSIX). */ +#define VKI_SIGILL 4 /* Illegal instruction (ANSI). */ +#define VKI_SIGTRAP 5 /* Trace trap (POSIX). */ +#define VKI_SIGIOT 6 /* IOT trap (4.2 BSD). */ +#define VKI_SIGABRT VKI_SIGIOT /* Abort (ANSI). */ +#define VKI_SIGEMT 7 +#define VKI_SIGFPE 8 /* Floating-point exception (ANSI). */ +#define VKI_SIGKILL 9 /* Kill, unblockable (POSIX). */ +#define VKI_SIGBUS 10 /* BUS error (4.2 BSD). */ +#define VKI_SIGSEGV 11 /* Segmentation violation (ANSI). */ +#define VKI_SIGSYS 12 +#define VKI_SIGPIPE 13 /* Broken pipe (POSIX). */ +#define VKI_SIGALRM 14 /* Alarm clock (POSIX). */ +#define VKI_SIGTERM 15 /* Termination (ANSI). */ +#define VKI_SIGUSR1 16 /* User-defined signal 1 (POSIX). */ +#define VKI_SIGUSR2 17 /* User-defined signal 2 (POSIX). */ +#define VKI_SIGCHLD 18 /* Child status has changed (POSIX). */ +#define VKI_SIGCLD VKI_SIGCHLD /* Same as SIGCHLD (System V). */ +#define VKI_SIGPWR 19 /* Power failure restart (System V). */ +#define VKI_SIGWINCH 20 /* Window size change (4.3 BSD, Sun). */ +#define VKI_SIGURG 21 /* Urgent condition on socket (4.2 BSD). */ +#define VKI_SIGIO 22 /* I/O now possible (4.2 BSD). */ +#define VKI_SIGPOLL VKI_SIGIO /* Pollable event occurred (System V). */ +#define VKI_SIGSTOP 23 /* Stop, unblockable (POSIX). */ +#define VKI_SIGTSTP 24 /* Keyboard stop (POSIX). */ +#define VKI_SIGCONT 25 /* Continue (POSIX). */ +#define VKI_SIGTTIN 26 /* Background read from tty (POSIX). */ +#define VKI_SIGTTOU 27 /* Background write to tty (POSIX). */ +#define VKI_SIGVTALRM 28 /* Virtual alarm clock (4.2 BSD). */ +#define VKI_SIGPROF 29 /* Profiling alarm clock (4.2 BSD). */ +#define VKI_SIGXCPU 30 /* CPU limit exceeded (4.2 BSD). */ +#define VKI_SIGXFSZ 31 /* File size limit exceeded (4.2 BSD). */ + +/* These should not be considered constants from userland. */ +#define VKI_SIGRTMIN 32 +// [[This was (_NSIG-1) in 2.4.X... not sure if it matters.]] +#define VKI_SIGRTMAX _VKI_NSIG + +#define VKI_SA_ONSTACK 0x08000000 +#define VKI_SA_RESETHAND 0x80000000 +#define VKI_SA_RESTART 0x10000000 +#define VKI_SA_SIGINFO 0x00000008 +#define VKI_SA_NODEFER 0x40000000 +#define VKI_SA_NOCLDWAIT 0x00010000 +#define VKI_SA_NOCLDSTOP 0x00000001 + +#define VKI_SA_NOMASK VKI_SA_NODEFER +#define VKI_SA_ONESHOT VKI_SA_RESETHAND +//#define VKI_SA_INTERRUPT 0x20000000 /* dummy -- ignored */ + +#define VKI_SA_RESTORER 0x04000000 + +#define VKI_SS_ONSTACK 1 +#define VKI_SS_DISABLE 2 + +struct vki_old_sigaction { + // [[Nb: a 'k' prefix is added to "sa_handler" because + // bits/sigaction.h (which gets dragged in somehow via signal.h) + // #defines it as something else. Since that is done for glibc's + // purposes, which we don't care about here, we use our own name.]] + unsigned long sa_flags; + __vki_sighandler_t ksa_handler; + vki_old_sigset_t sa_mask; + __vki_sigrestore_t sa_restorer; +}; + +struct vki_sigaction { + unsigned int sa_flags; + __vki_sighandler_t sa_handler; + vki_sigset_t sa_mask; +}; + + +struct vki_sigaction_base { + // [[See comment about extra 'k' above]] + unsigned long sa_flags; + __vki_sighandler_t ksa_handler; + + vki_sigset_t sa_mask; /* mask last for extensibility */ + __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; + vki_size_t ss_size; + int ss_flags; + +} vki_stack_t; + + +//---------------------------------------------------------------------- +// From 2.6.35.5/include/asm-mips/sigcontext.h +//---------------------------------------------------------------------- + +struct _vki_fpreg { + unsigned short significand[4]; + unsigned short exponent; +}; + +struct _vki_fpxreg { + unsigned short significand[4]; + unsigned short exponent; + unsigned short padding[3]; +}; + +struct _vki_xmmreg { + unsigned long element[4]; +}; + +struct _vki_fpstate { + /* Regular FPU environment */ + unsigned long cw; + unsigned long sw; + unsigned long tag; + unsigned long ipoff; + unsigned long cssel; + unsigned long dataoff; + unsigned long datasel; + struct _vki_fpreg _st[8]; + unsigned short status; + unsigned short magic; /* 0xffff = regular FPU data only */ + + /* FXSR FPU environment */ + unsigned long _fxsr_env[6]; /* FXSR FPU env is ignored */ + unsigned long mxcsr; + unsigned long reserved; + struct _vki_fpxreg _fxsr_st[8]; /* FXSR FPU reg data is ignored */ + struct _vki_xmmreg _xmm[8]; + unsigned long padding[56]; +}; + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/sigcontext.h +//---------------------------------------------------------------------- + +struct vki_sigcontext { + unsigned int sc_regmask; /* Unused */ + unsigned int sc_status; /* Unused */ + unsigned long long sc_pc; + unsigned long long sc_regs[32]; + unsigned long long sc_fpregs[32]; + unsigned int sc_acx; /* Was sc_ownedfp */ + unsigned int sc_fpc_csr; + unsigned int sc_fpc_eir; /* Unused */ + unsigned int sc_used_math; + unsigned int sc_dsp; /* dsp status, was sc_ssflags */ + unsigned long long sc_mdhi; + unsigned long long sc_mdlo; + unsigned long sc_hi1; /* Was sc_cause */ + unsigned long sc_lo1; /* Was sc_badvaddr */ + unsigned long sc_hi2; /* Was sc_sigset[4] */ + unsigned long sc_lo2; + unsigned long sc_hi3; + unsigned long sc_lo3; +}; + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/mman.h +//---------------------------------------------------------------------- + +#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 0x01000000 /* mprotect flag: extend change to start of growsdown vma */ +#define VKI_PROT_GROWSUP 0x02000000 /* mprotect flag: extend change to end of growsup vma */ + +#define VKI_MAP_SHARED 0x001 /* Share changes */ +#define VKI_MAP_PRIVATE 0x002 /* Changes are private */ +#define VKI_MAP_FIXED 0x010 /* Interpret addr exactly */ + +#define VKI_MAP_NORESERVE 0x0400 /* don't reserve swap pages */ + +/* These are linux-specific */ +#define VKI_MAP_NORESERVE 0x0400 /* don't check for reservations */ +#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_POPULATE 0x10000 /* populate (prefault) pagetables */ +#define VKI_MAP_NONBLOCK 0x20000 /* do not block on IO */ + + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/fcntl.h +//---------------------------------------------------------------------- + +#define VKI_O_RDONLY 00 +#define VKI_O_WRONLY 01 +#define VKI_O_RDWR 02 + +#define VKI_O_CREAT 0x0100 /* not fcntl */ +#define VKI_O_EXCL 0x0400 /* not fcntl */ + +#define VKI_O_TRUNC 0x0200 /* not fcntl */ + +#define VKI_O_APPEND 0x0008 +#define VKI_O_NONBLOCK 0x0080 +#define VKI_O_LARGEFILE 0x2000 + +#define VKI_AT_FDCWD -100 + +#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 14 +#define VKI_F_SETLK 6 +#define VKI_F_SETLKW 7 + +#define VKI_F_SETOWN 24 /* for sockets. */ +#define VKI_F_GETOWN 23 /* for sockets. */ +#define VKI_F_SETSIG 10 /* for sockets. */ +#define VKI_F_GETSIG 11 /* for sockets. */ + +#define VKI_F_SETOWN_EX 15 +#define VKI_F_GETOWN_EX 16 + +#define VKI_F_GETLK64 33 /* using 'struct flock64' */ +#define VKI_F_SETLK64 34 +#define VKI_F_SETLKW64 35 + +/* for F_[GET|SET]FL */ +#define VKI_FD_CLOEXEC 1 /* actually anything with low bit set goes */ + +#define VKI_F_LINUX_SPECIFIC_BASE 1024 + +struct vki_f_owner_ex { + int type; + __vki_kernel_pid_t pid; +}; + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/resource.h +//---------------------------------------------------------------------- + +#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 5 /* max number of open files */ + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/socket.h +//---------------------------------------------------------------------- + +#define VKI_SOL_SOCKET 0xffff +#define VKI_SO_TYPE 0x1008 + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-i386/sockios.h +//---------------------------------------------------------------------- + +#define VKI_SIOCSPGRP 0x8902 +#define VKI_SIOCGPGRP 0x8904 +#define VKI_SIOCGSTAMP 0x8906 /* Get stamp (timeval) */ +#define VKI_SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */ + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/stat.h +//---------------------------------------------------------------------- + +struct vki_stat { + unsigned st_dev; + long st_pad1[3]; /* Reserved for network id */ + unsigned long st_ino; + unsigned int st_mode; + unsigned long st_nlink; + unsigned int st_uid; + unsigned int st_gid; + unsigned st_rdev; + long st_pad2[2]; + long st_size; + long st_pad3; + /* + * Actually this should be timestruc_t st_atime, st_mtime and st_ctime + * but we don't have it under Linux. + */ + long st_atime; + long st_atime_nsec; + long st_mtime; + long st_mtime_nsec; + long st_ctime; + long st_ctime_nsec; + long st_blksize; + long st_blocks; + long st_pad4[14]; +}; + +/* + * This matches struct stat64 in glibc2.1, hence the absolutely insane + * amounts of padding around dev_t's. The memory layout is the same as of + * struct stat of the 64-bit kernel. + */ + +struct vki_stat64 { + unsigned long st_dev; + unsigned long st_pad0[3]; /* Reserved for st_dev expansion */ + + unsigned long long st_ino; + + unsigned int st_mode; + unsigned long st_nlink; + + unsigned int st_uid; + unsigned int st_gid; + + unsigned long st_rdev; + unsigned long st_pad1[3]; /* Reserved for st_rdev expansion */ + + long long st_size; + + /* + * Actually this should be timestruc_t st_atime, st_mtime and st_ctime + * but we don't have it under Linux. + */ + long st_atime; + unsigned long st_atime_nsec; /* Reserved for st_atime expansion */ + + long st_mtime; + unsigned long st_mtime_nsec; /* Reserved for st_mtime expansion */ + + long st_ctime; + unsigned long st_ctime_nsec; /* Reserved for st_ctime expansion */ + + unsigned long st_blksize; + unsigned long st_pad2; + + long long st_blocks; +}; + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/statfs.h +//---------------------------------------------------------------------- + +struct vki_statfs { + long f_type; + long f_bsize; + long f_frsize; /* Fragment size - unsupported */ + long f_blocks; + long f_bfree; + long f_files; + long f_ffree; + long f_bavail; + + /* Linux specials */ + __vki_kernel_fsid_t f_fsid; + long f_namelen; + long f_spare[6]; +}; + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/termios.h +//---------------------------------------------------------------------- + +struct vki_winsize { + unsigned short ws_row; + unsigned short ws_col; + unsigned short ws_xpixel; + unsigned short ws_ypixel; +}; + +#define NCC 8 +#define NCCS 23 +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 */ +}; + + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/termbits.h +//---------------------------------------------------------------------- + +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 */ +}; + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/ioctl.h +//---------------------------------------------------------------------- + +#define _VKI_IOC_NRBITS 8 +#define _VKI_IOC_TYPEBITS 8 +#define _VKI_IOC_SIZEBITS 14 +#define _VKI_IOC_DIRBITS 2 + +#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_WRITE 2U +#define _VKI_IOC_READ 4U + +#define _VKI_IOC(dir,type,nr,size) \ + (((dir) << _VKI_IOC_DIRSHIFT) | \ + ((type) << _VKI_IOC_TYPESHIFT) | \ + ((nr) << _VKI_IOC_NRSHIFT) | \ + ((size) << _VKI_IOC_SIZESHIFT)) + +/* provoke compile error for invalid uses of size argument */ +extern unsigned int __VKI_invalid_size_argument_for_IOC; +/* used to create numbers */ +#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))) + +/* used to decode ioctl numbers.. */ +#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) + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/ioctls.h +//---------------------------------------------------------------------- + +#define VKI_TCGETA 0x5401 +#define VKI_TCSETA 0x5402 /* Clashes with SNDCTL_TMR_START sound ioctl */ +#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_TIOCEXCL 0x740d /* set exclusive use of tty */ +#define VKI_TIOCNXCL 0x740e /* reset exclusive use of tty */ +#define VKI_TIOCOUTQ 0x7472 /* output queue size */ +#define VKI_TIOCSTI 0x5472 /* simulate terminal input */ +#define VKI_TIOCMGET 0x741d /* get all modem bits */ +#define VKI_TIOCMBIS 0x741b /* bis modem bits */ +#define VKI_TIOCMBIC 0x741c /* bic modem bits */ +#define VKI_TIOCMSET 0x741a /* set all modem bits */ +#define VKI_TIOCPKT 0x5470 /* pty: set/clear packet mode */ +#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 TIOCPKT_IOCTL 0x40 state change of pty driver */ +#define VKI_TIOCSWINSZ _VKI_IOW('t', 103, struct vki_winsize) /* set window size */ +#define VKI_TIOCGWINSZ _VKI_IOR('t', 104, struct vki_winsize) /* get window size */ +#define VKI_TIOCNOTTY 0x5471 /* void tty association */ +#define VKI_TIOCSETD 0x7401 +#define VKI_TIOCGETD 0x7400 + +#define VKI_FIOCLEX 0x6601 +#define VKI_FIONCLEX 0x6602 +#define VKI_FIOASYNC 0x667d +#define VKI_FIONBIO 0x667e +#define VKI_FIOQSIZE 0x667f + +#define VKI_TIOCGLTC 0x7474 /* get special local chars */ +#define VKI_TIOCSLTC 0x7475 /* set special local chars */ +#define VKI_TIOCSPGRP _VKI_IOW('t', 118, int) /* set pgrp of tty */ +#define VKI_TIOCGPGRP _VKI_IOR('t', 119, int) /* get pgrp of tty */ +#define VKI_TIOCCONS _VKI_IOW('t', 120, int) /* become virtual console */ + +#define VKI_FIONREAD 0x467f +#define VKI_TIOCINQ FIONREAD + +#define VKI_TIOCGETP 0x7408 +#define VKI_TIOCSETP 0x7409 +#define VKI_TIOCSETN 0x740a /* TIOCSETP wo flush */ + +#define VKI_TIOCSBRK 0x5427 /* BSD compatibility */ +#define VKI_TIOCCBRK 0x5428 /* BSD compatibility */ +#define VKI_TIOCGSID 0x7416 /* Return the session ID of FD */ +#define VKI_TIOCGPTN _VKI_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */ +#define VKI_TIOCSPTLCK _VKI_IOW('T',0x31, int) /* Lock/unlock Pty */ + +/* I hope the range from 0x5480 on is free ... */ +#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 */ + +//---------------------------------------------------------------------- +// From asm-generic/poll.h +//---------------------------------------------------------------------- + +/* These are specified by iBCS2 */ +#define VKI_POLLIN 0x0001 + +struct vki_pollfd { + int fd; + short events; + short revents; +}; +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/elf.h +//---------------------------------------------------------------------- + +#define VKI_ELF_NGREG 45 /* includes nip, msr, lr, etc. */ +#define VKI_ELF_NFPREG 33 /* includes fpscr */ + +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; + +#define VKI_AT_SYSINFO 32 +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/ucontext.h +//---------------------------------------------------------------------- + +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 */ +}; + +// CAB: TODO +typedef void vki_modify_ldt_t; + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/ipcbuf.h +//---------------------------------------------------------------------- + +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; +}; + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/sembuf.h +//---------------------------------------------------------------------- + +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; +}; + + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/msgbuf.h +//---------------------------------------------------------------------- + +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; +}; + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/ipc.h +//---------------------------------------------------------------------- + +struct vki_ipc_kludge { + struct vki_msgbuf __user *msgp; + long msgtyp; +}; + +#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 + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/shmbuf.h +//---------------------------------------------------------------------- + +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; +}; +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-mips/ptrace.h +//---------------------------------------------------------------------- + +struct vki_pt_regs { +#ifdef CONFIG_32BIT + /* Pad bytes for argument save space on the stack. */ + unsigned long pad0[6]; +#endif + /* Saved main processor registers. */ + unsigned long regs[32]; + + /* Saved special registers. */ + unsigned long cp0_status; + unsigned long hi; + unsigned long lo; +#ifdef CONFIG_CPU_HAS_SMARTMIPS + unsigned long acx; +#endif + unsigned long cp0_badvaddr; + unsigned long cp0_cause; + unsigned long cp0_epc; +#ifdef CONFIG_MIPS_MT_SMTC + unsigned long cp0_tcstatus; +#endif /* CONFIG_MIPS_MT_SMTC */ +#ifdef CONFIG_CPU_CAVIUM_OCTEON + unsigned long long mpl[3]; /* MTM{0,1,2} */ + unsigned long long mtp[3]; /* MTP{0,1,2} */ +#endif +} __attribute__ ((aligned (8))); + + +#define vki_user_regs_struct vki_pt_regs + +#define MIPS_lo lo +#define MIPS_hi hi +//#define MIPS_pc regs[32] +#define MIPS_r31 regs[31] +#define MIPS_r30 regs[30] +#define MIPS_r29 regs[29] +#define MIPS_r28 regs[28] +#define MIPS_r27 regs[27] +#define MIPS_r26 regs[26] +#define MIPS_r25 regs[25] +#define MIPS_r24 regs[24] +#define MIPS_r23 regs[23] +#define MIPS_r22 regs[22] +#define MIPS_r21 regs[21] +#define MIPS_r20 regs[20] +#define MIPS_r19 regs[19] +#define MIPS_r18 regs[18] +#define MIPS_r17 regs[17] +#define MIPS_r16 regs[16] +#define MIPS_r15 regs[15] +#define MIPS_r14 regs[14] +#define MIPS_r13 regs[13] +#define MIPS_r12 regs[12] +#define MIPS_r11 regs[11] +#define MIPS_r10 regs[10] +#define MIPS_r9 regs[9] +#define MIPS_r8 regs[8] +#define MIPS_r7 regs[7] +#define MIPS_r6 regs[6] +#define MIPS_r5 regs[5] +#define MIPS_r4 regs[4] +#define MIPS_r3 regs[3] +#define MIPS_r2 regs[2] +#define MIPS_r1 regs[1] +#define MIPS_r0 regs[0] + +#define VKI_PTRACE_GETREGS 12 +#define VKI_PTRACE_SETREGS 13 +#define VKI_PTRACE_GETFPREGS 14 +#define VKI_PTRACE_SETFPREGS 15 +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm-generic/siginfo.h +//---------------------------------------------------------------------- +#define HAVE_ARCH_SIGINFO_T + +typedef union vki_sigval { + int sival_int; + void __user *sival_ptr; +} vki_sigval_t; + +#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 + +typedef struct vki_siginfo { + int si_signo; + int si_code; + int si_errno; + 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; + +//---------------------------------------------------------------------- +// From linux-2.6.35.5/include/asm/break.h +//---------------------------------------------------------------------- +#define VKI_BRK_OVERFLOW 6 /* Overflow check */ +#define VKI_BRK_DIVZERO 7 /* Divide by zero check */ + +#endif // __VKI_MIPS32_LINUX_H + + +/*--------------------------------------------------------------------*/ +/*--- end vki-mips32-linux.h ---*/ +/*--------------------------------------------------------------------*/ Added: trunk/coregrind/m_syswrap/syscall-mips32-linux.S (+215 -0) =================================================================== --- trunk/coregrind/m_syswrap/syscall-mips32-linux.S 2012-06-07 10:13:21 +01:00 (rev 12616) +++ trunk/coregrind/m_syswrap/syscall-mips32-linux.S 2012-06-07 10:23:23 +01:00 (rev 12617) @@ -0,0 +1,215 @@ + +/*--------------------------------------------------------------------*/ +/*--- Support for doing system calls. syscall-mips32-linux.S ---*/ +/*--------------------------------------------------------------------*/ + +/* + This file is part of Valgrind, a dynamic binary instrumentation + framework. + + Copyright (C) 2010-2012 RT-RK + mip...@rt... + + 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. +*/ + +#if defined(VGP_mips32_linux) + +#include "pub_core_basics_asm.h" +#include "pub_core_vkiscnums_asm.h" +#include "libvex_guest_offsets.h" + + +/*----------------------------------------------------------------*/ +/* + Perform a syscall for the client. This will run a syscall + with the client's specific per-thread signal mask. + + The structure of this function is such that, if the syscall is + interrupted by a signal, we can determine exactly what + execution state we were in with respect to the execution of + the syscall by examining the value of IP in the signal + handler. This means that we can always do the appropriate + thing to precisely emulate the kernel's signal/syscall + interactions. + + The syscall number is taken from the argument, even though it + should also be in regs->v0. The syscall result is written + back to regs->v0 on completion. + + Returns 0 if the syscall was successfully called (even if the + syscall itself failed), or a nonzero error code in the lowest + 8 bits if one of the sigprocmasks failed (there's no way to + determine which one failed). And there's no obvious way to + recover from that either, but nevertheless we want to know. + + VG_(fixup_guest_state_after_syscall_interrupted) does the + thread state fixup in the case where we were interrupted by a + signal. + + Prototype: + + UWord ML_(do_syscall_for_client_WRK)( + Int syscallno, // $4 - a0 + void* guest_state, // $5 - a1 + const vki_sigset_t *sysmask, // $6 - a2 + const vki_sigset_t *postmask, // $7 - a3 + Int nsigwords) // stack +*/ +/* from vki_arch.h */ +#define VKI_SIG_SETMASK 3 + +.globl ML_(do_syscall_for_client_WRK) +ML_(do_syscall_for_client_WRK): + + subu $29, $29, 56 #set up the steck frame, + sw $4, 52($29) + sw $5, 48($29) + sw $6, 44($29) + sw $7, 40($29) + sw $31, 36($29) + sw $30, 32($29) + sw $16, 28($29) + sw $17, 24($29) + sw $18, 20($29) + sw $19, 16($29) + sw $20, 12($29) + sw $21, 8($29) + sw $22, 4($29) + sw $23, 0($29) + addu $30, $29, 56 + + + /* Set the signal mask which should be current during the syscall. */ + +1: li $2, __NR_rt_sigprocmask + li $4, VKI_SIG_SETMASK + move $5, $6 /* sysmask */ + move $6, $7 /* postmask */ + lw $7, 72($29) /* nsigwo... [truncated message content] |