2 /*--------------------------------------------------------------------*/
3 /*--- Support for doing system calls. syscall-nanomips-linux.S ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2017-2018 RT-RK
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.
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.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, see <http://www.gnu.org/licenses/>.
25 The GNU General Public License is contained in the file COPYING.
28 #include "pub_core_basics_asm.h"
30 #if defined(VGP_nanomips_linux)
32 #include "pub_core_vkiscnums_asm.h"
33 #include "libvex_guest_offsets.h"
36 /*----------------------------------------------------------------*/
38 Perform a syscall for the client. This will run a syscall
39 with the client's specific per-thread signal mask.
41 The structure of this function is such that, if the syscall is
42 interrupted by a signal, we can determine exactly what
43 execution state we were in with respect to the execution of
44 the syscall by examining the value of IP in the signal
45 handler. This means that we can always do the appropriate
46 thing to precisely emulate the kernel's signal/syscall
49 The syscall number is taken from the argument, even though it
50 should also be in regs->v0. The syscall result is written
51 back to regs->v0 on completion.
53 Returns 0 if the syscall was successfully called (even if the
54 syscall itself failed), or a nonzero error code in the lowest
55 8 bits if one of the sigprocmasks failed (there's no way to
56 determine which one failed). And there's no obvious way to
57 recover from that either, but nevertheless we want to know.
59 VG_(fixup_guest_state_after_syscall_interrupted) does the
60 thread state fixup in the case where we were interrupted by a
65 UWord ML_(do_syscall_for_client_WRK)(
67 void* guest_state, // a1
68 const vki_sigset_t *sysmask, // a2
69 const vki_sigset_t *postmask, // a3
73 #define VKI_SIG_SETMASK 2
74 .globl ML_(do_syscall_for_client_WRK)
75 ML_(do_syscall_for_client_WRK):
79 1: li $t4, __NR_rt_sigprocmask
80 li $a0, VKI_SIG_SETMASK
81 move $a1, $a2 # sysmask
82 move $a2, $a3 # postmask
83 move $a3, $a4 # nsigwords
88 lw $t4, 28($sp) # t4 = syscallno
89 lw $t0, 24($sp) # t0 = &guest_state
91 lw $a0, OFFSET_mips32_r4($t0)
92 lw $a1, OFFSET_mips32_r5($t0)
93 lw $a2, OFFSET_mips32_r6($t0)
94 lw $a3, OFFSET_mips32_r7($t0)
95 lw $a4, OFFSET_mips32_r8($t0)
96 lw $a5, OFFSET_mips32_r9($t0)
97 lw $a6, OFFSET_mips32_r10($t0)
98 lw $a7, OFFSET_mips32_r11($t0)
101 3: lw $t0, 24($sp) # t0 = &guest_state
103 sw $a0, OFFSET_mips32_r4($t0)
105 4: li $t4, __NR_rt_sigprocmask
106 li $a0, VKI_SIG_SETMASK
112 bnezc $a0, 5f # error
117 5: #error, return 0x8000
124 /* export the ranges so that
125 VG_(fixup_guest_state_after_syscall_interrupted) can do the
128 .globl ML_(blksys_setup)
129 .globl ML_(blksys_restart)
130 .globl ML_(blksys_complete)
131 .globl ML_(blksys_committed)
132 .globl ML_(blksys_finished)
133 ML_(blksys_setup): .long 1b
134 ML_(blksys_restart): .long 2b
135 ML_(blksys_complete): .long 3b
136 ML_(blksys_committed): .long 4b
137 ML_(blksys_finished): .long 6b
141 /* Let the linker know we don't need an executable stack */
144 /*--------------------------------------------------------------------*/
145 /*--- end syscall-nanomips-linux.S ---*/
146 /*--------------------------------------------------------------------*/