sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 1 | |
sewardj | 331dc98 | 2005-12-22 20:14:57 +0000 | [diff] [blame] | 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- Support for doing system calls. syscall-ppc64-linux.S ---*/ |
| 4 | /*--------------------------------------------------------------------*/ |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
| 9 | |
sewardj | 0f157dd | 2013-10-18 14:27:36 +0000 | [diff] [blame] | 10 | Copyright (C) 2005-2013 Paul Mackerras <paulus@samba.org> |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 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 | |
carll | 582d582 | 2014-08-07 23:35:54 +0000 | [diff] [blame] | 30 | #if defined(VGP_ppc64le_linux) |
njn | 8b68b64 | 2009-06-24 00:37:09 +0000 | [diff] [blame] | 31 | |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 32 | #include "pub_core_basics_asm.h" |
njn | 1a1e95c | 2009-06-03 06:50:06 +0000 | [diff] [blame] | 33 | #include "pub_core_vkiscnums_asm.h" |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 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 |
sewardj | 331dc98 | 2005-12-22 20:14:57 +0000 | [diff] [blame] | 55 | syscall itself failed), or a nonzero error code in the lowest |
sewardj | 2537616 | 2005-12-22 19:28:37 +0000 | [diff] [blame] | 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. |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 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 | |
sewardj | 2537616 | 2005-12-22 19:28:37 +0000 | [diff] [blame] | 66 | UWord ML_(do_syscall_for_client_WRK)( |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 67 | Int syscallno, // r3 |
| 68 | void* guest_state, // r4 |
| 69 | const vki_sigset_t *sysmask, // r5 |
| 70 | const vki_sigset_t *postmask, // r6 |
njn | cda2f0f | 2009-05-18 02:12:08 +0000 | [diff] [blame] | 71 | Int sigsetSzB) // r7 |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 72 | */ |
| 73 | /* from vki_arch.h */ |
| 74 | #define VKI_SIG_SETMASK 2 |
| 75 | |
cerion | 297c88f | 2005-12-22 15:53:12 +0000 | [diff] [blame] | 76 | .align 2 |
| 77 | .globl ML_(do_syscall_for_client_WRK) |
carll | 582d582 | 2014-08-07 23:35:54 +0000 | [diff] [blame] | 78 | #if _CALL_ELF == 2 |
| 79 | .type .ML_(do_syscall_for_client_WRK),@function |
| 80 | ML_(do_syscall_for_client_WRK): |
| 81 | 0: addis 2,12,.TOC.-0b@ha |
| 82 | addi 2,2,.TOC.-0b@l |
| 83 | .localentry ML_(do_syscall_for_client_WRK), .-ML_(do_syscall_for_client_WRK) |
| 84 | #else |
cerion | 297c88f | 2005-12-22 15:53:12 +0000 | [diff] [blame] | 85 | .section ".opd","aw" |
| 86 | .align 3 |
carll | 582d582 | 2014-08-07 23:35:54 +0000 | [diff] [blame] | 87 | ML_(do_syscall_for_client_WRK): |
cerion | 297c88f | 2005-12-22 15:53:12 +0000 | [diff] [blame] | 88 | .quad .ML_(do_syscall_for_client_WRK),.TOC.@tocbase,0 |
| 89 | .previous |
carll | 582d582 | 2014-08-07 23:35:54 +0000 | [diff] [blame] | 90 | #endif |
| 91 | #if _CALL_ELF == 2 |
| 92 | 0: addis 2,12,.TOC.-0b@ha |
| 93 | addi 2,2,.TOC.-0b@l |
| 94 | .localentry ML_(do_syscall_for_client_WRK), .-ML_(do_syscall_for_client_WRK) |
| 95 | #endif |
| 96 | .type .ML_(do_syscall_for_client_WRK),@function |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 97 | .globl .ML_(do_syscall_for_client_WRK) |
| 98 | .ML_(do_syscall_for_client_WRK): |
| 99 | /* make a stack frame */ |
cerion | 297c88f | 2005-12-22 15:53:12 +0000 | [diff] [blame] | 100 | stdu 1,-80(1) |
| 101 | std 31,72(1) |
| 102 | std 30,64(1) |
| 103 | std 29,56(1) |
| 104 | std 28,48(1) |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 105 | mr 31,3 /* syscall number */ |
| 106 | mr 30,4 /* guest_state */ |
| 107 | mr 29,6 /* postmask */ |
njn | cda2f0f | 2009-05-18 02:12:08 +0000 | [diff] [blame] | 108 | mr 28,7 /* sigsetSzB */ |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 109 | |
| 110 | /* set the signal mask for doing the system call */ |
| 111 | /* set up for sigprocmask(SIG_SETMASK, sysmask, postmask) */ |
sewardj | 2537616 | 2005-12-22 19:28:37 +0000 | [diff] [blame] | 112 | 1: li 0,__NR_rt_sigprocmask |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 113 | li 3,VKI_SIG_SETMASK |
| 114 | mr 4,5 |
| 115 | mr 5,6 |
sewardj | 2537616 | 2005-12-22 19:28:37 +0000 | [diff] [blame] | 116 | mr 6,7 |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 117 | sc /* set the mask */ |
| 118 | bso 7f /* if the sigprocmask fails */ |
| 119 | |
| 120 | /* load up syscall args from the threadstate */ |
| 121 | ld 3,OFFSET_ppc64_GPR3(30) |
| 122 | ld 4,OFFSET_ppc64_GPR4(30) |
| 123 | ld 5,OFFSET_ppc64_GPR5(30) |
| 124 | ld 6,OFFSET_ppc64_GPR6(30) |
| 125 | ld 7,OFFSET_ppc64_GPR7(30) |
| 126 | ld 8,OFFSET_ppc64_GPR8(30) |
| 127 | mr 0,31 /* syscall number */ |
| 128 | 2: sc /* do the syscall */ |
| 129 | |
| 130 | /* put the result back in the threadstate */ |
| 131 | 3: std 3,OFFSET_ppc64_GPR3(30) /* gst->GPR3 = sc result */ |
| 132 | /* copy cr0.so back to simulated state */ |
| 133 | mfcr 5 /* r5 = CR */ |
| 134 | rlwinm 5,5,4,31,31 /* r5 = (CR >> 28) & 1 */ |
| 135 | stb 5,OFFSET_ppc64_CR0_0(30) /* gst->CR0.SO = cr0.so */ |
| 136 | |
| 137 | /* block signals again */ |
| 138 | /* set up for sigprocmask(SIG_SETMASK, postmask, NULL) */ |
sewardj | 2537616 | 2005-12-22 19:28:37 +0000 | [diff] [blame] | 139 | 4: li 0,__NR_rt_sigprocmask |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 140 | li 3,VKI_SIG_SETMASK |
| 141 | mr 4,29 |
| 142 | li 5,0 |
| 143 | mr 6,28 |
| 144 | sc /* set the mask */ |
| 145 | bso 7f /* if the sigprocmask fails */ |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 146 | /* now safe from signals */ |
sewardj | 2537616 | 2005-12-22 19:28:37 +0000 | [diff] [blame] | 147 | li 3,0 /* SUCCESS */ |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 148 | |
| 149 | /* pop off stack frame */ |
cerion | 297c88f | 2005-12-22 15:53:12 +0000 | [diff] [blame] | 150 | 5: ld 28,48(1) |
| 151 | ld 29,56(1) |
| 152 | ld 30,64(1) |
| 153 | ld 31,72(1) |
| 154 | addi 1,1,80 |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 155 | blr |
| 156 | |
sewardj | 331dc98 | 2005-12-22 20:14:57 +0000 | [diff] [blame] | 157 | /* failure: return 0x8000 | error code */ |
sewardj | 2537616 | 2005-12-22 19:28:37 +0000 | [diff] [blame] | 158 | 7: ori 3,3,0x8000 /* FAILURE -- ensure return value is nonzero */ |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 159 | b 5b |
carll | 582d582 | 2014-08-07 23:35:54 +0000 | [diff] [blame] | 160 | #if _CALL_ELF == 2 |
| 161 | .size .ML_(do_syscall_for_client_WRK),.-.ML_(do_syscall_for_client_WRK) |
| 162 | #else |
| 163 | .size .ML_(do_syscall_for_client_WRK),.-.ML_(do_syscall_for_client_WRK) |
| 164 | #endif |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 165 | .section .rodata |
| 166 | /* export the ranges so that |
| 167 | VG_(fixup_guest_state_after_syscall_interrupted) can do the |
| 168 | right thing */ |
| 169 | |
| 170 | .globl ML_(blksys_setup) |
| 171 | .globl ML_(blksys_restart) |
| 172 | .globl ML_(blksys_complete) |
| 173 | .globl ML_(blksys_committed) |
| 174 | .globl ML_(blksys_finished) |
sewardj | 4246fc6 | 2006-01-02 19:06:08 +0000 | [diff] [blame] | 175 | ML_(blksys_setup): .quad 1b |
| 176 | ML_(blksys_restart): .quad 2b |
| 177 | ML_(blksys_complete): .quad 3b |
| 178 | ML_(blksys_committed): .quad 4b |
| 179 | ML_(blksys_finished): .quad 5b |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 180 | |
cerion | 297c88f | 2005-12-22 15:53:12 +0000 | [diff] [blame] | 181 | |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 182 | /* Let the linker know we don't need an executable stack */ |
| 183 | .section .note.GNU-stack,"",@progbits |
| 184 | |
sewardj | 6ba50d1 | 2014-08-08 08:58:03 +0000 | [diff] [blame] | 185 | #endif // defined(VGP_ppc64le_linux) |
njn | 8b68b64 | 2009-06-24 00:37:09 +0000 | [diff] [blame] | 186 | |
sewardj | 331dc98 | 2005-12-22 20:14:57 +0000 | [diff] [blame] | 187 | /*--------------------------------------------------------------------*/ |
| 188 | /*--- end ---*/ |
| 189 | /*--------------------------------------------------------------------*/ |