Home | History | Annotate | Download | only in m_syswrap
      1 
      2 /*--------------------------------------------------------------------*/
      3 /*--- Support for doing system calls.      syscall-mips32-linux.S  ---*/
      4 /*--------------------------------------------------------------------*/
      5 
      6 /*
      7    This file is part of Valgrind, a dynamic binary instrumentation
      8    framework.
      9 
     10    Copyright (C) 2010-2012 RT-RK
     11       mips-valgrind (at) rt-rk.com
     12 
     13    This program is free software; you can redistribute it and/or
     14    modify it under the terms of the GNU General Public License as
     15    published by the Free Software Foundation; either version 2 of the
     16    License, or (at your option) any later version.
     17 
     18    This program is distributed in the hope that it will be useful, but
     19    WITHOUT ANY WARRANTY; without even the implied warranty of
     20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     21    General Public License for more details.
     22 
     23    You should have received a copy of the GNU General Public License
     24    along with this program; if not, write to the Free Software
     25    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
     26    02111-1307, USA.
     27 
     28    The GNU General Public License is contained in the file COPYING.
     29 */
     30 
     31 #if defined(VGP_mips32_linux)
     32 
     33 #include "pub_core_basics_asm.h"
     34 #include "pub_core_vkiscnums_asm.h"
     35 #include "libvex_guest_offsets.h"
     36 
     37 
     38 /*----------------------------------------------------------------*/
     39 /*
     40         Perform a syscall for the client.  This will run a syscall
     41         with the client's specific per-thread signal mask.
     42 
     43         The structure of this function is such that, if the syscall is
     44         interrupted by a signal, we can determine exactly what
     45         execution state we were in with respect to the execution of
     46         the syscall by examining the value of IP in the signal
     47         handler.  This means that we can always do the appropriate
     48         thing to precisely emulate the kernel's signal/syscall
     49         interactions.
     50 
     51         The syscall number is taken from the argument, even though it
     52         should also be in regs->v0.  The syscall result is written
     53         back to regs->v0 on completion.
     54 
     55         Returns 0 if the syscall was successfully called (even if the
     56         syscall itself failed), or a nonzero error code in the lowest
     57         8 bits if one of the sigprocmasks failed (there's no way to
     58         determine which one failed).  And there's no obvious way to
     59         recover from that either, but nevertheless we want to know.
     60 
     61         VG_(fixup_guest_state_after_syscall_interrupted) does the
     62         thread state fixup in the case where we were interrupted by a
     63         signal.
     64 
     65         Prototype:
     66 
     67    UWord ML_(do_syscall_for_client_WRK)(
     68               Int syscallno,                 // $4 - a0
     69               void* guest_state,             // $5 - a1
     70               const vki_sigset_t *sysmask,   // $6 - a2
     71               const vki_sigset_t *postmask,  // $7 - a3
     72               Int nsigwords)                 // stack
     73 */
     74 /* from vki_arch.h */
     75 #define VKI_SIG_SETMASK 3
     76 
     77 .globl ML_(do_syscall_for_client_WRK)
     78 ML_(do_syscall_for_client_WRK):
     79 
     80     subu $29, $29, 56  #set up the steck frame,
     81     sw $4, 52($29)
     82     sw $5, 48($29)
     83     sw $6, 44($29)
     84     sw $7, 40($29)
     85     sw $31, 36($29)
     86     sw $30, 32($29)
     87     sw $16, 28($29)
     88     sw $17, 24($29)
     89     sw $18, 20($29)
     90     sw $19, 16($29)
     91     sw $20, 12($29)
     92     sw $21, 8($29)
     93     sw $22, 4($29)
     94     sw $23, 0($29)
     95     addu $30, $29, 56
     96 
     97 
     98     /* Set the signal mask which should be current during the syscall. */
     99 
    100 1:  li $2, __NR_rt_sigprocmask
    101     li $4, VKI_SIG_SETMASK
    102     move $5, $6 /* sysmask */
    103     move $6, $7 /* postmask */
    104     lw $7, 72($29) /* nsigwords */
    105     syscall
    106     nop
    107 
    108 # TODO: this should remain, keep it just for now
    109     bnez $7, 7f
    110     nop
    111 
    112     lw $8, 48($29)    /* t0 == ThreadState */
    113 
    114     lw $2, 52($29) /* v0 == syscallno */
    115     lw $4, OFFSET_mips32_r4($8)
    116     lw $5, OFFSET_mips32_r5($8)
    117     lw $6, OFFSET_mips32_r6($8)
    118     lw $7, OFFSET_mips32_r7($8)
    119     subu $29, $29, 24  #set up the steck frame,
    120     lw $9, OFFSET_mips32_r29($8)
    121     lw $10, 16($9)
    122     sw $10, 16($29)
    123     lw $10, 20($9)
    124     sw $10, 20($29)
    125 
    126 2:  syscall
    127 
    128 3:  addu $29, $29, 24  #set up the steck frame,
    129 
    130     lw $8, 48($29) /* t0 == ThreadState */
    131     sw $2, OFFSET_mips32_r2($8)
    132     sw $3, OFFSET_mips32_r3($8)
    133     sw $7, OFFSET_mips32_r7($8)
    134 
    135 4:  li $2, __NR_rt_sigprocmask
    136     li $4, VKI_SIG_SETMASK
    137     lw $5, 40($29)
    138     li $6, 0
    139     lw $7, 72($29) /* nsigwords */
    140     syscall
    141     nop
    142 
    143     bnez $7, 7f
    144     nop
    145 
    146     /* Success */
    147     li $2, 0
    148 
    149 5:  lw $4, 52($29)
    150     lw $5, 48($29)
    151     lw $6, 44($29)
    152     lw $7, 40($29)
    153     lw $31, 36($29)
    154     lw $30, 32($29)
    155     lw $16, 28($29)
    156     lw $17, 24($29)
    157     lw $18, 20($29)
    158     lw $19, 16($29)
    159     lw $20, 12($29)
    160     lw $21, 8($29)
    161     lw $22, 4($29)
    162     lw $23, 0($29)
    163     addu $29, $29, 56 #release the stack frame.
    164 
    165     jr $31
    166     nop
    167 
    168 7:  /* Failure: return 0x8000 | error code */
    169     li $2, 0x8000
    170 
    171     lw $4, 52($29)
    172     lw $5, 48($29)
    173     lw $6, 44($29)
    174     lw $7, 40($29)
    175     lw $31, 36($29)
    176     lw $30, 32($29)
    177     lw $16, 28($29)
    178     lw $17, 24($29)
    179     lw $18, 20($29)
    180     lw $19, 16($29)
    181     lw $20, 12($29)
    182     lw $21, 8($29)
    183     lw $22, 4($29)
    184     lw $23, 0($29)
    185     addu $29, $29, 56 #release the stack frame.
    186 
    187     jr $31
    188     nop
    189 
    190 .section .rodata
    191 /* export the ranges so that
    192    VG_(fixup_guest_state_after_syscall_interrupted) can do the
    193    right thing */
    194 
    195 .globl ML_(blksys_setup)
    196 .globl ML_(blksys_restart)
    197 .globl ML_(blksys_complete)
    198 .globl ML_(blksys_committed)
    199 .globl ML_(blksys_finished)
    200 ML_(blksys_setup):      .long 1b
    201 ML_(blksys_restart):    .long 2b
    202 ML_(blksys_complete):   .long 3b
    203 ML_(blksys_committed):  .long 4b
    204 ML_(blksys_finished):   .long 5b
    205 .previous
    206 /* Let the linker know we don't need an executable stack */
    207 .section .note.GNU-stack,"",%progbits
    208 
    209 
    210 
    211 #endif // defined(VGP_mips32_linux)
    212 
    213 /*--------------------------------------------------------------------*/
    214 /*--- end                                                          ---*/
    215 /*--------------------------------------------------------------------*/
    216