1 2 /*--------------------------------------------------------------------*/ 3 /*--- Support for doing system calls. syscall-mips64-linux.S ---*/ 4 /*--------------------------------------------------------------------*/ 5 6 /* 7 This file is part of Valgrind, a dynamic binary instrumentation 8 framework. 9 10 Copyright (C) 2010-2013 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_mips64_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 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 PC 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->v0. The syscall result is written 52 back to regs->v0 on completion. 53 54 VG_(fixup_guest_state_after_syscall_interrupted) does the 55 thread state fixup in the case where we were interrupted by a 56 signal. 57 58 Prototype: 59 60 UWord ML_(do_syscall_for_client_WRK)( 61 Int syscallno, // $4 - a0 62 void* guest_state, // $5 - a1 63 const vki_sigset_t *sysmask, // $6 - a2 64 const vki_sigset_t *postmask, // $7 - a3 65 Int nsigwords) // $8 - a4 66 */ 67 68 /* from vki_arch.h */ 69 #define VKI_SIG_SETMASK 3 70 71 .globl ML_(do_syscall_for_client_WRK) 72 ML_(do_syscall_for_client_WRK): 73 74 /* save regs $a0 - $a4 on stack */ 75 daddiu $29, $29, -48 76 sd $4, 0($29) /* syscallno */ 77 sd $5, 8($29) /* guest_state */ 78 sd $6, 16($29) /* sysmask */ 79 sd $7, 24($29) /* postmask */ 80 sd $8, 32($29) /* nsigwords */ 81 82 1: li $2, __NR_rt_sigprocmask 83 li $4, VKI_SIG_SETMASK 84 move $5, $6 /* sysmask */ 85 move $6, $7 /* postmask */ 86 move $7, $8 /* nsigwords */ 87 syscall 88 89 bnez $7, 7f 90 nop 91 92 /* Actually do the client syscall */ 93 ld $5, 8($29) /* guest_state */ 94 ld $4, OFFSET_mips64_r4($5) /* a0 */ 95 96 ld $6, OFFSET_mips64_r6($5) /* a2 */ 97 ld $7, OFFSET_mips64_r7($5) /* a3 */ 98 ld $8, OFFSET_mips64_r8($5) /* a4 */ 99 ld $9, OFFSET_mips64_r9($5) /* a5 */ 100 101 ld $5, OFFSET_mips64_r5($5) /* a1 */ 102 ld $2, 0($29) /* syscallno */ 103 104 2: syscall 105 106 /* Saving return values into Guest state */ 107 3: ld $5, 8($29) /* guest_state */ 108 sd $2, OFFSET_mips64_r2($5) /* v0 */ 109 sd $7, OFFSET_mips64_r7($5) /* a3 */ 110 111 4: li $2, __NR_rt_sigprocmask 112 li $4, VKI_SIG_SETMASK 113 ld $5, 24($29) /* postmask */ 114 move $6, $0 /* 0 (zero) */ 115 ld $7, 32($29) /* nsigwords */ 116 syscall 117 118 bnez $7, 7f 119 nop 120 121 5: /* restore 29 and return */ 122 daddiu $29, $29, 48 123 jr $31 124 nop 125 126 7: /* error */ 127 daddiu $29, $29, 48 128 li $2, 0x8000 129 jr $31 130 nop 131 132 .section .rodata 133 /* export the ranges so that 134 VG_(fixup_guest_state_after_syscall_interrupted) can do the 135 right thing */ 136 137 .globl ML_(blksys_setup) 138 .globl ML_(blksys_restart) 139 .globl ML_(blksys_complete) 140 .globl ML_(blksys_committed) 141 .globl ML_(blksys_finished) 142 ML_(blksys_setup): .quad 1b 143 ML_(blksys_restart): .quad 2b 144 ML_(blksys_complete): .quad 3b 145 ML_(blksys_committed): .quad 4b 146 ML_(blksys_finished): .quad 5b 147 .previous 148 /* Let the linker know we don't need an executable stack */ 149 .section .note.GNU-stack,"",%progbits 150 151 #endif // defined(VGP_mips64_linux) 152 153 /*--------------------------------------------------------------------*/ 154 /*--- end ---*/ 155 /*--------------------------------------------------------------------*/ 156