njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 1 | |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- Trampoline code page stuff. m_trampoline.S ---*/ |
| 4 | /*--------------------------------------------------------------------*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 5 | |
| 6 | /* |
njn | b9c427c | 2004-12-01 14:14:42 +0000 | [diff] [blame] | 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 9 | |
njn | 5361242 | 2005-03-12 16:22:54 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2005 Julian Seward |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 11 | jseward@acm.org |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 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 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 28 | The GNU General Public License is contained in the file COPYING. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 29 | */ |
| 30 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 31 | #include "pub_core_basics_asm.h" |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 32 | #include "vki_unistd.h" |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 33 | |
sewardj | 54cacf0 | 2002-04-12 23:24:59 +0000 | [diff] [blame] | 34 | /* ------------------ SIMULATED CPU HELPERS ------------------ */ |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 35 | /* |
| 36 | Replacements for some functions to do with vsyscalls and signals. |
| 37 | This code runs on the simulated CPU. |
sewardj | 54cacf0 | 2002-04-12 23:24:59 +0000 | [diff] [blame] | 38 | */ |
sewardj | a48a493 | 2005-09-29 11:09:56 +0000 | [diff] [blame] | 39 | |
| 40 | /*---------------------- x86-linux ----------------------*/ |
| 41 | #if defined(VGP_x86_linux) |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 42 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 43 | # define UD2_16 ud2 ; ud2 ; ud2 ; ud2 ;ud2 ; ud2 ; ud2 ; ud2 |
| 44 | # define UD2_64 UD2_16 ; UD2_16 ; UD2_16 ; UD2_16 |
| 45 | # define UD2_256 UD2_64 ; UD2_64 ; UD2_64 ; UD2_64 |
| 46 | # define UD2_1024 UD2_256 ; UD2_256 ; UD2_256 ; UD2_256 |
| 47 | # define UD2_PAGE UD2_1024 ; UD2_1024 ; UD2_1024 ; UD2_1024 |
| 48 | |
| 49 | /* a leading page of unexecutable code */ |
| 50 | UD2_PAGE |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 51 | |
| 52 | .global VG_(trampoline_stuff_start) |
| 53 | VG_(trampoline_stuff_start): |
| 54 | |
| 55 | .global VG_(x86_linux_SUBST_FOR_sigreturn) |
| 56 | VG_(x86_linux_SUBST_FOR_sigreturn): |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 57 | /* This is a very specific sequence which GDB uses to |
| 58 | recognize signal handler frames. */ |
| 59 | popl %eax |
| 60 | movl $__NR_sigreturn, %eax |
| 61 | int $0x80 |
| 62 | ud2 |
| 63 | |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 64 | .global VG_(x86_linux_SUBST_FOR_rt_sigreturn) |
| 65 | VG_(x86_linux_SUBST_FOR_rt_sigreturn): |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 66 | /* Likewise for rt signal frames */ |
| 67 | movl $__NR_rt_sigreturn, %eax |
| 68 | int $0x80 |
| 69 | ud2 |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 70 | |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 71 | .global VG_(x86_linux_REDIR_FOR__dl_sysinfo_int80) |
| 72 | VG_(x86_linux_REDIR_FOR__dl_sysinfo_int80): |
| 73 | /* We can point our sysinfo stuff here */ |
fitzhardinge | 9236079 | 2003-12-24 10:11:11 +0000 | [diff] [blame] | 74 | int $0x80 |
| 75 | ret |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 76 | |
| 77 | .global VG_(trampoline_stuff_end) |
| 78 | VG_(trampoline_stuff_end): |
njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 79 | |
sewardj | a48a493 | 2005-09-29 11:09:56 +0000 | [diff] [blame] | 80 | /* and a trailing page of unexecutable code */ |
| 81 | UD2_PAGE |
| 82 | |
| 83 | # undef UD2_16 |
| 84 | # undef UD2_64 |
| 85 | # undef UD2_256 |
| 86 | # undef UD2_1024 |
| 87 | # undef UD2_PAGE |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 88 | |
sewardj | a48a493 | 2005-09-29 11:09:56 +0000 | [diff] [blame] | 89 | /*---------------------- amd64-linux ----------------------*/ |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 90 | #else |
| 91 | #if defined(VGP_amd64_linux) |
njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 92 | |
sewardj | a48a493 | 2005-09-29 11:09:56 +0000 | [diff] [blame] | 93 | # define UD2_16 ud2 ; ud2 ; ud2 ; ud2 ;ud2 ; ud2 ; ud2 ; ud2 |
| 94 | # define UD2_64 UD2_16 ; UD2_16 ; UD2_16 ; UD2_16 |
| 95 | # define UD2_256 UD2_64 ; UD2_64 ; UD2_64 ; UD2_64 |
| 96 | # define UD2_1024 UD2_256 ; UD2_256 ; UD2_256 ; UD2_256 |
| 97 | # define UD2_PAGE UD2_1024 ; UD2_1024 ; UD2_1024 ; UD2_1024 |
| 98 | |
| 99 | /* a leading page of unexecutable code */ |
| 100 | UD2_PAGE |
| 101 | |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 102 | .global VG_(trampoline_stuff_start) |
| 103 | VG_(trampoline_stuff_start): |
| 104 | |
| 105 | .global VG_(amd64_linux_SUBST_FOR_rt_sigreturn) |
| 106 | VG_(amd64_linux_SUBST_FOR_rt_sigreturn): |
| 107 | /* This is a very specific sequence which GDB uses to |
| 108 | recognize signal handler frames. */ |
njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 109 | movq $__NR_rt_sigreturn, %rax |
| 110 | syscall |
| 111 | ud2 |
| 112 | |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 113 | .global VG_(amd64_linux_REDIR_FOR_vgettimeofday) |
| 114 | VG_(amd64_linux_REDIR_FOR_vgettimeofday): |
njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 115 | movq $__NR_gettimeofday, %rax |
| 116 | syscall |
| 117 | ret |
| 118 | |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 119 | .global VG_(amd64_linux_REDIR_FOR_vtime) |
| 120 | VG_(amd64_linux_REDIR_FOR_vtime): |
njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 121 | movq $__NR_time, %rax |
| 122 | syscall |
| 123 | ret |
| 124 | |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 125 | .global VG_(trampoline_stuff_end) |
| 126 | VG_(trampoline_stuff_end): |
njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 127 | |
sewardj | a48a493 | 2005-09-29 11:09:56 +0000 | [diff] [blame] | 128 | /* and a trailing page of unexecutable code */ |
| 129 | UD2_PAGE |
| 130 | |
| 131 | # undef UD2_16 |
| 132 | # undef UD2_64 |
| 133 | # undef UD2_256 |
| 134 | # undef UD2_1024 |
| 135 | # undef UD2_PAGE |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 136 | |
sewardj | 05b5fc1 | 2005-06-21 09:56:56 +0000 | [diff] [blame] | 137 | /*---------------- ppc32-linux ----------------*/ |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 138 | #else |
| 139 | #if defined(VGP_ppc32_linux) |
| 140 | |
sewardj | a48a493 | 2005-09-29 11:09:56 +0000 | [diff] [blame] | 141 | # define UD2_16 trap ; trap ; trap; trap |
| 142 | # define UD2_64 UD2_16 ; UD2_16 ; UD2_16 ; UD2_16 |
| 143 | # define UD2_256 UD2_64 ; UD2_64 ; UD2_64 ; UD2_64 |
| 144 | # define UD2_1024 UD2_256 ; UD2_256 ; UD2_256 ; UD2_256 |
| 145 | # define UD2_PAGE UD2_1024 ; UD2_1024 ; UD2_1024 ; UD2_1024 |
| 146 | |
| 147 | /* a leading page of unexecutable code */ |
| 148 | UD2_PAGE |
| 149 | |
sewardj | 05b5fc1 | 2005-06-21 09:56:56 +0000 | [diff] [blame] | 150 | .global VG_(trampoline_stuff_start) |
| 151 | VG_(trampoline_stuff_start): |
cerion | 85665ca | 2005-06-20 15:51:07 +0000 | [diff] [blame] | 152 | |
sewardj | ad50be3 | 2005-08-18 11:54:30 +0000 | [diff] [blame] | 153 | /* There's no particular reason that this needs to be handwritten |
| 154 | assembly, but since that's what this file contains, here's a |
| 155 | simple strlen implementation (written in C and compiled by gcc.) |
| 156 | */ |
| 157 | .global VG_(ppc32_linux_REDIR_FOR_strlen) |
sewardj | 0b6941e | 2005-10-12 10:00:56 +0000 | [diff] [blame] | 158 | .type VG_(ppc32_linux_REDIR_FOR_strlen), @function |
sewardj | ad50be3 | 2005-08-18 11:54:30 +0000 | [diff] [blame] | 159 | VG_(ppc32_linux_REDIR_FOR_strlen): |
| 160 | lbz 4,0(3) |
| 161 | li 9,0 |
| 162 | cmpwi 0,4,0 |
sewardj | 5e7b230 | 2005-10-01 19:12:08 +0000 | [diff] [blame] | 163 | beq- 0,.L18 |
| 164 | .L19: |
sewardj | ad50be3 | 2005-08-18 11:54:30 +0000 | [diff] [blame] | 165 | lbzu 5,1(3) |
| 166 | addi 9,9,1 |
| 167 | cmpwi 0,5,0 |
sewardj | 5e7b230 | 2005-10-01 19:12:08 +0000 | [diff] [blame] | 168 | bne+ 0,.L19 |
| 169 | .L18: |
sewardj | ad50be3 | 2005-08-18 11:54:30 +0000 | [diff] [blame] | 170 | mr 3,9 |
| 171 | blr |
sewardj | 0b6941e | 2005-10-12 10:00:56 +0000 | [diff] [blame] | 172 | .size VG_(ppc32_linux_REDIR_FOR_strlen), .-VG_(ppc32_linux_REDIR_FOR_strlen) |
sewardj | ad50be3 | 2005-08-18 11:54:30 +0000 | [diff] [blame] | 173 | |
sewardj | 5e7b230 | 2005-10-01 19:12:08 +0000 | [diff] [blame] | 174 | /* Ditto strcmp */ |
| 175 | .global VG_(ppc32_linux_REDIR_FOR_strcmp) |
sewardj | 0b6941e | 2005-10-12 10:00:56 +0000 | [diff] [blame] | 176 | .type VG_(ppc32_linux_REDIR_FOR_strcmp), @function |
sewardj | 5e7b230 | 2005-10-01 19:12:08 +0000 | [diff] [blame] | 177 | VG_(ppc32_linux_REDIR_FOR_strcmp): |
| 178 | .L20: |
| 179 | lbz 0,0(3) |
| 180 | cmpwi 7,0,0 |
| 181 | bne- 7,.L21 |
| 182 | lbz 0,0(4) |
| 183 | li 11,0 |
| 184 | cmpwi 7,0,0 |
| 185 | beq- 7,.L22 |
| 186 | .L21: |
| 187 | lbz 0,0(3) |
| 188 | li 11,-1 |
| 189 | cmpwi 7,0,0 |
| 190 | beq- 7,.L22 |
| 191 | lbz 0,0(4) |
| 192 | li 11,1 |
| 193 | cmpwi 7,0,0 |
| 194 | beq- 7,.L22 |
| 195 | lbz 9,0(3) |
| 196 | lbz 0,0(4) |
| 197 | li 11,-1 |
| 198 | cmplw 7,9,0 |
| 199 | blt- 7,.L22 |
| 200 | lbz 9,0(3) |
| 201 | lbz 0,0(4) |
| 202 | li 11,1 |
| 203 | addi 3,3,1 |
| 204 | addi 4,4,1 |
| 205 | cmplw 7,9,0 |
| 206 | ble+ 7,.L20 |
| 207 | .L22: |
| 208 | mr 3,11 |
| 209 | blr |
sewardj | 0b6941e | 2005-10-12 10:00:56 +0000 | [diff] [blame] | 210 | .size VG_(ppc32_linux_REDIR_FOR_strcmp), .-VG_(ppc32_linux_REDIR_FOR_strcmp) |
sewardj | 5e7b230 | 2005-10-01 19:12:08 +0000 | [diff] [blame] | 211 | |
sewardj | 31d8342 | 2005-10-15 02:00:41 +0000 | [diff] [blame] | 212 | /* Ditto index/strchr */ |
| 213 | .global VG_(ppc32_linux_REDIR_FOR_strchr) |
| 214 | .type VG_(ppc32_linux_REDIR_FOR_strchr), @function |
| 215 | VG_(ppc32_linux_REDIR_FOR_strchr): |
| 216 | lbz 0,0(3) |
| 217 | cmpw 7,4,0 |
| 218 | beqlr 7 |
| 219 | cmpwi 7,0,0 |
| 220 | beq 7,.L307 |
| 221 | .p2align 4,,15 |
| 222 | .L310: |
| 223 | lbzu 0,1(3) |
| 224 | cmpw 7,0,4 |
| 225 | cmpwi 6,0,0 |
| 226 | beq 7,.L313 |
| 227 | bne 6,.L310 |
| 228 | .L307: |
| 229 | li 3,0 |
| 230 | blr |
| 231 | .L313: |
| 232 | blr |
| 233 | .size VG_(ppc32_linux_REDIR_FOR_strchr),.-VG_(ppc32_linux_REDIR_FOR_strchr) |
| 234 | |
sewardj | 05b5fc1 | 2005-06-21 09:56:56 +0000 | [diff] [blame] | 235 | .global VG_(trampoline_stuff_end) |
| 236 | VG_(trampoline_stuff_end): |
| 237 | |
sewardj | a48a493 | 2005-09-29 11:09:56 +0000 | [diff] [blame] | 238 | # undef UD2_16 |
| 239 | # undef UD2_64 |
| 240 | # undef UD2_256 |
| 241 | # undef UD2_1024 |
| 242 | # undef UD2_PAGE |
sewardj | 05b5fc1 | 2005-06-21 09:56:56 +0000 | [diff] [blame] | 243 | |
sewardj | 05b5fc1 | 2005-06-21 09:56:56 +0000 | [diff] [blame] | 244 | /*---------------- unknown ----------------*/ |
njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 245 | #else |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 246 | # error Unknown platform |
| 247 | |
njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 248 | #endif |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 249 | #endif |
| 250 | #endif |
| 251 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 252 | |
thughes | 4ad52d0 | 2004-06-27 17:37:21 +0000 | [diff] [blame] | 253 | /* Let the linker know we don't need an executable stack */ |
| 254 | .section .note.GNU-stack,"",@progbits |
| 255 | |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 256 | /*--------------------------------------------------------------------*/ |
| 257 | /*--- end ---*/ |
| 258 | /*--------------------------------------------------------------------*/ |