Home | History | Annotate | Download | only in m_syswrap
      1 
      2 /*--------------------------------------------------------------------*/
      3 /*--- Support for doing system calls.        syscall-ppc32-linux.S ---*/
      4 /*--------------------------------------------------------------------*/
      5 
      6 /*
      7   This file is part of Valgrind, a dynamic binary instrumentation
      8   framework.
      9 
     10   Copyright (C) 2005-2012 Paul Mackerras (paulus (at) samba.org)
     11 
     12   This program is free software; you can redistribute it and/or
     13   modify it under the terms of the GNU General Public License as
     14   published by the Free Software Foundation; either version 2 of the
     15   License, or (at your option) any later version.
     16 
     17   This program is distributed in the hope that it will be useful, but
     18   WITHOUT ANY WARRANTY; without even the implied warranty of
     19   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     20   General Public License for more details.
     21 
     22   You should have received a copy of the GNU General Public License
     23   along with this program; if not, write to the Free Software
     24   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
     25   02111-1307, USA.
     26 
     27   The GNU General Public License is contained in the file COPYING.
     28 */
     29 
     30 #if defined(VGP_ppc32_linux)
     31 
     32 #include "pub_core_basics_asm.h"
     33 #include "pub_core_vkiscnums_asm.h"
     34 #include "libvex_guest_offsets.h"
     35 
     36 
     37 /*----------------------------------------------------------------*/
     38 /*
     39         Perform a syscall for the client.  This will run a syscall
     40         with the client's specific per-thread signal mask.
     41 
     42         The structure of this function is such that, if the syscall is
     43         interrupted by a signal, we can determine exactly what
     44         execution state we were in with respect to the execution of
     45         the syscall by examining the value of NIP in the signal
     46         handler.  This means that we can always do the appropriate
     47         thing to precisely emulate the kernel's signal/syscall
     48         interactions.
     49 
     50         The syscall number is taken from the argument, even though it
     51         should also be in regs->m_gpr[0].  The syscall result is written
     52         back to regs->m_gpr[3]/m_xer/m_result on completion.
     53 
     54         Returns 0 if the syscall was successfully called (even if the
     55         syscall itself failed), or a nonzero error code in the lowest
     56 	8 bits if one of the sigprocmasks failed (there's no way to
     57 	determine which one failed).  And there's no obvious way to
     58 	recover from that either, but nevertheless we want to know.
     59 
     60         VG_(fixup_guest_state_after_syscall_interrupted) does the
     61 	thread state fixup in the case where we were interrupted by a
     62 	signal.
     63 
     64         Prototype:
     65 
     66 	UWord ML_(do_syscall_for_client_WRK)(
     67 				  Int syscallno,		// r3
     68 				  void* guest_state,		// r4
     69 				  const vki_sigset_t *sysmask,	// r5
     70 				  const vki_sigset_t *postmask,	// r6
     71 				  Int sigsetSzB)		// r7
     72 */
     73 /* from vki_arch.h */
     74 #define VKI_SIG_SETMASK 2
     75 
     76 .globl ML_(do_syscall_for_client_WRK)
     77 ML_(do_syscall_for_client_WRK):
     78         /* make a stack frame */
     79         stwu    1,-32(1)
     80         stw     31,28(1)
     81         stw     30,24(1)
     82         stw     29,20(1)
     83         stw     28,16(1)
     84         mr      31,3            /* syscall number */
     85         mr      30,4            /* guest_state */
     86         mr      29,6            /* postmask */
     87         mr      28,7            /* sigsetSzB */
     88 
     89         /* set the signal mask for doing the system call */
     90         /* set up for sigprocmask(SIG_SETMASK, sysmask, postmask) */
     91 1:      li      0,__NR_rt_sigprocmask
     92         li      3,VKI_SIG_SETMASK
     93         mr      4,5
     94         mr      5,6
     95 	mr	6,7
     96         sc                      /* set the mask */
     97         bso     7f              /* if the sigprocmask fails */
     98 
     99         /* load up syscall args from the threadstate */
    100         lwz     3,OFFSET_ppc32_GPR3(30)
    101         lwz     4,OFFSET_ppc32_GPR4(30)
    102         lwz     5,OFFSET_ppc32_GPR5(30)
    103         lwz     6,OFFSET_ppc32_GPR6(30)
    104         lwz     7,OFFSET_ppc32_GPR7(30)
    105         lwz     8,OFFSET_ppc32_GPR8(30)
    106         mr      0,31            /* syscall number */
    107 2:      sc                      /* do the syscall */
    108 
    109         /* put the result back in the threadstate  */
    110 3:	stw     3,OFFSET_ppc32_GPR3(30)     /* gst->GPR3 = sc result */
    111 	/* copy cr0.so back to simulated state */
    112 	mfcr    5                           /* r5 = CR               */
    113 	rlwinm	5,5,4,31,31                 /* r5 = (CR >> 28) & 1   */
    114         stb     5,OFFSET_ppc32_CR0_0(30)    /* gst->CR0.SO = cr0.so  */
    115 
    116         /* block signals again */
    117 	/* set up for sigprocmask(SIG_SETMASK, postmask, NULL) */
    118 4:      li      0,__NR_rt_sigprocmask
    119         li      3,VKI_SIG_SETMASK
    120         mr      4,29
    121         li      5,0
    122         mr      6,28
    123         sc                      /* set the mask */
    124         bso     7f              /* if the sigprocmask fails */
    125         /* now safe from signals */
    126 	li	3,0		/* SUCCESS */
    127 
    128         /* pop off stack frame */
    129 5:      lwz     28,16(1)
    130         lwz     29,20(1)
    131         lwz     30,24(1)
    132         lwz     31,28(1)
    133         addi    1,1,32
    134         blr
    135 
    136 	/* failure: return 0x8000 | error code */
    137 7:      ori	3,3,0x8000	/* FAILURE -- ensure return value is nonzero */
    138         b       5b
    139 
    140 .section .rodata
    141 /* export the ranges so that
    142    VG_(fixup_guest_state_after_syscall_interrupted) can do the
    143    right thing */
    144 
    145 .globl ML_(blksys_setup)
    146 .globl ML_(blksys_restart)
    147 .globl ML_(blksys_complete)
    148 .globl ML_(blksys_committed)
    149 .globl ML_(blksys_finished)
    150 ML_(blksys_setup):     .long 1b
    151 ML_(blksys_restart):   .long 2b
    152 ML_(blksys_complete):  .long 3b
    153 ML_(blksys_committed): .long 4b
    154 ML_(blksys_finished):  .long 5b
    155 
    156 .previous
    157 
    158 /* Let the linker know we don't need an executable stack */
    159 .section .note.GNU-stack,"",@progbits
    160 
    161 #endif // defined(VGP_ppc32_linux)
    162 
    163 /*--------------------------------------------------------------------*/
    164 /*--- end                                                          ---*/
    165 /*--------------------------------------------------------------------*/
    166