njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 1 | /*--------------------------------------------------------------------*/ |
| 2 | /*--- Machine-related stuff. m_machine.c ---*/ |
| 3 | /*--------------------------------------------------------------------*/ |
| 4 | |
| 5 | /* |
| 6 | This file is part of Valgrind, a dynamic binary instrumentation |
| 7 | framework. |
| 8 | |
sewardj | 03f8d3f | 2012-08-05 15:46:46 +0000 | [diff] [blame] | 9 | Copyright (C) 2000-2012 Julian Seward |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 10 | jseward@acm.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 | |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 30 | #include "pub_core_basics.h" |
sewardj | 4cfea4f | 2006-10-14 19:26:10 +0000 | [diff] [blame] | 31 | #include "pub_core_vki.h" |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 32 | #include "pub_core_libcsetjmp.h" // setjmp facilities |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 33 | #include "pub_core_threadstate.h" |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 34 | #include "pub_core_libcassert.h" |
| 35 | #include "pub_core_libcbase.h" |
sewardj | 2c3f2ea | 2011-04-13 15:40:10 +0000 | [diff] [blame] | 36 | #include "pub_core_libcfile.h" |
| 37 | #include "pub_core_mallocfree.h" |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 38 | #include "pub_core_machine.h" |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 39 | #include "pub_core_cpuid.h" |
bart | 1581e74 | 2009-01-13 07:49:14 +0000 | [diff] [blame] | 40 | #include "pub_core_libcsignal.h" // for ppc32 messing with SIGILL and SIGFPE |
sewardj | 3b0cae7 | 2009-05-28 17:15:41 +0000 | [diff] [blame] | 41 | #include "pub_core_debuglog.h" |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 42 | |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 43 | |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 44 | #define INSTR_PTR(regs) ((regs).vex.VG_INSTR_PTR) |
| 45 | #define STACK_PTR(regs) ((regs).vex.VG_STACK_PTR) |
| 46 | #define FRAME_PTR(regs) ((regs).vex.VG_FRAME_PTR) |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 47 | |
sewardj | 1dbd337 | 2010-08-22 12:21:14 +0000 | [diff] [blame] | 48 | Addr VG_(get_IP) ( ThreadId tid ) { |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 49 | return INSTR_PTR( VG_(threads)[tid].arch ); |
| 50 | } |
sewardj | 1dbd337 | 2010-08-22 12:21:14 +0000 | [diff] [blame] | 51 | Addr VG_(get_SP) ( ThreadId tid ) { |
| 52 | return STACK_PTR( VG_(threads)[tid].arch ); |
| 53 | } |
| 54 | Addr VG_(get_FP) ( ThreadId tid ) { |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 55 | return FRAME_PTR( VG_(threads)[tid].arch ); |
| 56 | } |
| 57 | |
sewardj | 1dbd337 | 2010-08-22 12:21:14 +0000 | [diff] [blame] | 58 | void VG_(set_IP) ( ThreadId tid, Addr ip ) { |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 59 | INSTR_PTR( VG_(threads)[tid].arch ) = ip; |
| 60 | } |
sewardj | 1dbd337 | 2010-08-22 12:21:14 +0000 | [diff] [blame] | 61 | void VG_(set_SP) ( ThreadId tid, Addr sp ) { |
| 62 | STACK_PTR( VG_(threads)[tid].arch ) = sp; |
| 63 | } |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 64 | |
| 65 | void VG_(get_UnwindStartRegs) ( /*OUT*/UnwindStartRegs* regs, |
| 66 | ThreadId tid ) |
| 67 | { |
| 68 | # if defined(VGA_x86) |
| 69 | regs->r_pc = (ULong)VG_(threads)[tid].arch.vex.guest_EIP; |
| 70 | regs->r_sp = (ULong)VG_(threads)[tid].arch.vex.guest_ESP; |
| 71 | regs->misc.X86.r_ebp |
| 72 | = VG_(threads)[tid].arch.vex.guest_EBP; |
| 73 | # elif defined(VGA_amd64) |
| 74 | regs->r_pc = VG_(threads)[tid].arch.vex.guest_RIP; |
| 75 | regs->r_sp = VG_(threads)[tid].arch.vex.guest_RSP; |
| 76 | regs->misc.AMD64.r_rbp |
| 77 | = VG_(threads)[tid].arch.vex.guest_RBP; |
| 78 | # elif defined(VGA_ppc32) |
| 79 | regs->r_pc = (ULong)VG_(threads)[tid].arch.vex.guest_CIA; |
sewardj | f5f1e12 | 2010-01-02 13:24:58 +0000 | [diff] [blame] | 80 | regs->r_sp = (ULong)VG_(threads)[tid].arch.vex.guest_GPR1; |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 81 | regs->misc.PPC32.r_lr |
| 82 | = VG_(threads)[tid].arch.vex.guest_LR; |
| 83 | # elif defined(VGA_ppc64) |
| 84 | regs->r_pc = VG_(threads)[tid].arch.vex.guest_CIA; |
sewardj | f5f1e12 | 2010-01-02 13:24:58 +0000 | [diff] [blame] | 85 | regs->r_sp = VG_(threads)[tid].arch.vex.guest_GPR1; |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 86 | regs->misc.PPC64.r_lr |
| 87 | = VG_(threads)[tid].arch.vex.guest_LR; |
| 88 | # elif defined(VGA_arm) |
sewardj | 1dbd337 | 2010-08-22 12:21:14 +0000 | [diff] [blame] | 89 | regs->r_pc = (ULong)VG_(threads)[tid].arch.vex.guest_R15T; |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 90 | regs->r_sp = (ULong)VG_(threads)[tid].arch.vex.guest_R13; |
| 91 | regs->misc.ARM.r14 |
| 92 | = VG_(threads)[tid].arch.vex.guest_R14; |
| 93 | regs->misc.ARM.r12 |
| 94 | = VG_(threads)[tid].arch.vex.guest_R12; |
| 95 | regs->misc.ARM.r11 |
| 96 | = VG_(threads)[tid].arch.vex.guest_R11; |
sewardj | fa5ce56 | 2010-09-23 22:05:59 +0000 | [diff] [blame] | 97 | regs->misc.ARM.r7 |
| 98 | = VG_(threads)[tid].arch.vex.guest_R7; |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 99 | # elif defined(VGA_s390x) |
| 100 | regs->r_pc = (ULong)VG_(threads)[tid].arch.vex.guest_IA; |
| 101 | regs->r_sp = (ULong)VG_(threads)[tid].arch.vex.guest_SP; |
| 102 | regs->misc.S390X.r_fp |
| 103 | = VG_(threads)[tid].arch.vex.guest_r11; |
| 104 | regs->misc.S390X.r_lr |
| 105 | = VG_(threads)[tid].arch.vex.guest_r14; |
sewardj | 5db1540 | 2012-06-07 09:13:21 +0000 | [diff] [blame] | 106 | # elif defined(VGA_mips32) |
| 107 | regs->r_pc = VG_(threads)[tid].arch.vex.guest_PC; |
| 108 | regs->r_sp = VG_(threads)[tid].arch.vex.guest_r29; |
| 109 | regs->misc.MIPS32.r30 |
| 110 | = VG_(threads)[tid].arch.vex.guest_r30; |
| 111 | regs->misc.MIPS32.r31 |
| 112 | = VG_(threads)[tid].arch.vex.guest_r31; |
| 113 | regs->misc.MIPS32.r28 |
| 114 | = VG_(threads)[tid].arch.vex.guest_r28; |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 115 | # else |
| 116 | # error "Unknown arch" |
| 117 | # endif |
| 118 | } |
| 119 | |
| 120 | |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 121 | void VG_(set_syscall_return_shadows) ( ThreadId tid, |
| 122 | /* shadow vals for the result */ |
| 123 | UWord s1res, UWord s2res, |
| 124 | /* shadow vals for the error val */ |
| 125 | UWord s1err, UWord s2err ) |
| 126 | { |
| 127 | # if defined(VGP_x86_linux) |
| 128 | VG_(threads)[tid].arch.vex_shadow1.guest_EAX = s1res; |
| 129 | VG_(threads)[tid].arch.vex_shadow2.guest_EAX = s2res; |
| 130 | # elif defined(VGP_amd64_linux) |
| 131 | VG_(threads)[tid].arch.vex_shadow1.guest_RAX = s1res; |
| 132 | VG_(threads)[tid].arch.vex_shadow2.guest_RAX = s2res; |
| 133 | # elif defined(VGP_ppc32_linux) || defined(VGP_ppc64_linux) |
| 134 | VG_(threads)[tid].arch.vex_shadow1.guest_GPR3 = s1res; |
| 135 | VG_(threads)[tid].arch.vex_shadow2.guest_GPR3 = s2res; |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 136 | # elif defined(VGP_arm_linux) |
| 137 | VG_(threads)[tid].arch.vex_shadow1.guest_R0 = s1res; |
| 138 | VG_(threads)[tid].arch.vex_shadow2.guest_R0 = s2res; |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 139 | # elif defined(VGO_darwin) |
| 140 | // GrP fixme darwin syscalls may return more values (2 registers plus error) |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 141 | # elif defined(VGP_s390x_linux) |
| 142 | VG_(threads)[tid].arch.vex_shadow1.guest_r2 = s1res; |
| 143 | VG_(threads)[tid].arch.vex_shadow2.guest_r2 = s2res; |
sewardj | 5db1540 | 2012-06-07 09:13:21 +0000 | [diff] [blame] | 144 | # elif defined(VGP_mips32_linux) |
| 145 | VG_(threads)[tid].arch.vex_shadow1.guest_r2 = s1res; |
| 146 | VG_(threads)[tid].arch.vex_shadow2.guest_r2 = s2res; |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 147 | # else |
| 148 | # error "Unknown plat" |
| 149 | # endif |
| 150 | } |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 151 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 152 | void |
| 153 | VG_(get_shadow_regs_area) ( ThreadId tid, |
| 154 | /*DST*/UChar* dst, |
njn | c4431bf | 2009-01-15 21:29:24 +0000 | [diff] [blame] | 155 | /*SRC*/Int shadowNo, PtrdiffT offset, SizeT size ) |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 156 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 157 | void* src; |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 158 | ThreadState* tst; |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 159 | vg_assert(shadowNo == 0 || shadowNo == 1 || shadowNo == 2); |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 160 | vg_assert(VG_(is_valid_tid)(tid)); |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 161 | // Bounds check |
| 162 | vg_assert(0 <= offset && offset < sizeof(VexGuestArchState)); |
| 163 | vg_assert(offset + size <= sizeof(VexGuestArchState)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 164 | // Copy |
| 165 | tst = & VG_(threads)[tid]; |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 166 | src = NULL; |
| 167 | switch (shadowNo) { |
| 168 | case 0: src = (void*)(((Addr)&(tst->arch.vex)) + offset); break; |
| 169 | case 1: src = (void*)(((Addr)&(tst->arch.vex_shadow1)) + offset); break; |
| 170 | case 2: src = (void*)(((Addr)&(tst->arch.vex_shadow2)) + offset); break; |
| 171 | } |
| 172 | tl_assert(src != NULL); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 173 | VG_(memcpy)( dst, src, size); |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 174 | } |
| 175 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 176 | void |
| 177 | VG_(set_shadow_regs_area) ( ThreadId tid, |
njn | c4431bf | 2009-01-15 21:29:24 +0000 | [diff] [blame] | 178 | /*DST*/Int shadowNo, PtrdiffT offset, SizeT size, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 179 | /*SRC*/const UChar* src ) |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 180 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 181 | void* dst; |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 182 | ThreadState* tst; |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 183 | vg_assert(shadowNo == 0 || shadowNo == 1 || shadowNo == 2); |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 184 | vg_assert(VG_(is_valid_tid)(tid)); |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 185 | // Bounds check |
| 186 | vg_assert(0 <= offset && offset < sizeof(VexGuestArchState)); |
| 187 | vg_assert(offset + size <= sizeof(VexGuestArchState)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 188 | // Copy |
| 189 | tst = & VG_(threads)[tid]; |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 190 | dst = NULL; |
| 191 | switch (shadowNo) { |
| 192 | case 0: dst = (void*)(((Addr)&(tst->arch.vex)) + offset); break; |
| 193 | case 1: dst = (void*)(((Addr)&(tst->arch.vex_shadow1)) + offset); break; |
| 194 | case 2: dst = (void*)(((Addr)&(tst->arch.vex_shadow2)) + offset); break; |
| 195 | } |
| 196 | tl_assert(dst != NULL); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 197 | VG_(memcpy)( dst, src, size); |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | |
philippe | a22f59d | 2012-01-26 23:13:52 +0000 | [diff] [blame] | 201 | static void apply_to_GPs_of_tid(ThreadId tid, void (*f)(ThreadId, HChar*, Addr)) |
njn | 6ace3ea | 2005-06-17 03:06:27 +0000 | [diff] [blame] | 202 | { |
philippe | a22f59d | 2012-01-26 23:13:52 +0000 | [diff] [blame] | 203 | VexGuestArchState* vex = &(VG_(get_ThreadState)(tid)->arch.vex); |
njn | 6ace3ea | 2005-06-17 03:06:27 +0000 | [diff] [blame] | 204 | #if defined(VGA_x86) |
philippe | a22f59d | 2012-01-26 23:13:52 +0000 | [diff] [blame] | 205 | (*f)(tid, "EAX", vex->guest_EAX); |
| 206 | (*f)(tid, "ECX", vex->guest_ECX); |
| 207 | (*f)(tid, "EDX", vex->guest_EDX); |
| 208 | (*f)(tid, "EBX", vex->guest_EBX); |
| 209 | (*f)(tid, "ESI", vex->guest_ESI); |
| 210 | (*f)(tid, "EDI", vex->guest_EDI); |
| 211 | (*f)(tid, "ESP", vex->guest_ESP); |
| 212 | (*f)(tid, "EBP", vex->guest_EBP); |
njn | 6ace3ea | 2005-06-17 03:06:27 +0000 | [diff] [blame] | 213 | #elif defined(VGA_amd64) |
philippe | a22f59d | 2012-01-26 23:13:52 +0000 | [diff] [blame] | 214 | (*f)(tid, "RAX", vex->guest_RAX); |
| 215 | (*f)(tid, "RCX", vex->guest_RCX); |
| 216 | (*f)(tid, "RDX", vex->guest_RDX); |
| 217 | (*f)(tid, "RBX", vex->guest_RBX); |
| 218 | (*f)(tid, "RSI", vex->guest_RSI); |
| 219 | (*f)(tid, "RDI", vex->guest_RDI); |
| 220 | (*f)(tid, "RSP", vex->guest_RSP); |
| 221 | (*f)(tid, "RBP", vex->guest_RBP); |
| 222 | (*f)(tid, "R8" , vex->guest_R8 ); |
| 223 | (*f)(tid, "R9" , vex->guest_R9 ); |
| 224 | (*f)(tid, "R10", vex->guest_R10); |
| 225 | (*f)(tid, "R11", vex->guest_R11); |
| 226 | (*f)(tid, "R12", vex->guest_R12); |
| 227 | (*f)(tid, "R13", vex->guest_R13); |
| 228 | (*f)(tid, "R14", vex->guest_R14); |
| 229 | (*f)(tid, "R15", vex->guest_R15); |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 230 | #elif defined(VGA_ppc32) || defined(VGA_ppc64) |
philippe | a22f59d | 2012-01-26 23:13:52 +0000 | [diff] [blame] | 231 | (*f)(tid, "GPR0" , vex->guest_GPR0 ); |
| 232 | (*f)(tid, "GPR1" , vex->guest_GPR1 ); |
| 233 | (*f)(tid, "GPR2" , vex->guest_GPR2 ); |
| 234 | (*f)(tid, "GPR3" , vex->guest_GPR3 ); |
| 235 | (*f)(tid, "GPR4" , vex->guest_GPR4 ); |
| 236 | (*f)(tid, "GPR5" , vex->guest_GPR5 ); |
| 237 | (*f)(tid, "GPR6" , vex->guest_GPR6 ); |
| 238 | (*f)(tid, "GPR7" , vex->guest_GPR7 ); |
| 239 | (*f)(tid, "GPR8" , vex->guest_GPR8 ); |
| 240 | (*f)(tid, "GPR9" , vex->guest_GPR9 ); |
| 241 | (*f)(tid, "GPR10", vex->guest_GPR10); |
| 242 | (*f)(tid, "GPR11", vex->guest_GPR11); |
| 243 | (*f)(tid, "GPR12", vex->guest_GPR12); |
| 244 | (*f)(tid, "GPR13", vex->guest_GPR13); |
| 245 | (*f)(tid, "GPR14", vex->guest_GPR14); |
| 246 | (*f)(tid, "GPR15", vex->guest_GPR15); |
| 247 | (*f)(tid, "GPR16", vex->guest_GPR16); |
| 248 | (*f)(tid, "GPR17", vex->guest_GPR17); |
| 249 | (*f)(tid, "GPR18", vex->guest_GPR18); |
| 250 | (*f)(tid, "GPR19", vex->guest_GPR19); |
| 251 | (*f)(tid, "GPR20", vex->guest_GPR20); |
| 252 | (*f)(tid, "GPR21", vex->guest_GPR21); |
| 253 | (*f)(tid, "GPR22", vex->guest_GPR22); |
| 254 | (*f)(tid, "GPR23", vex->guest_GPR23); |
| 255 | (*f)(tid, "GPR24", vex->guest_GPR24); |
| 256 | (*f)(tid, "GPR25", vex->guest_GPR25); |
| 257 | (*f)(tid, "GPR26", vex->guest_GPR26); |
| 258 | (*f)(tid, "GPR27", vex->guest_GPR27); |
| 259 | (*f)(tid, "GPR28", vex->guest_GPR28); |
| 260 | (*f)(tid, "GPR29", vex->guest_GPR29); |
| 261 | (*f)(tid, "GPR30", vex->guest_GPR30); |
| 262 | (*f)(tid, "GPR31", vex->guest_GPR31); |
| 263 | (*f)(tid, "CTR" , vex->guest_CTR ); |
| 264 | (*f)(tid, "LR" , vex->guest_LR ); |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 265 | #elif defined(VGA_arm) |
philippe | a22f59d | 2012-01-26 23:13:52 +0000 | [diff] [blame] | 266 | (*f)(tid, "R0" , vex->guest_R0 ); |
| 267 | (*f)(tid, "R1" , vex->guest_R1 ); |
| 268 | (*f)(tid, "R2" , vex->guest_R2 ); |
| 269 | (*f)(tid, "R3" , vex->guest_R3 ); |
| 270 | (*f)(tid, "R4" , vex->guest_R4 ); |
| 271 | (*f)(tid, "R5" , vex->guest_R5 ); |
| 272 | (*f)(tid, "R6" , vex->guest_R6 ); |
| 273 | (*f)(tid, "R8" , vex->guest_R8 ); |
| 274 | (*f)(tid, "R9" , vex->guest_R9 ); |
| 275 | (*f)(tid, "R10", vex->guest_R10); |
| 276 | (*f)(tid, "R11", vex->guest_R11); |
| 277 | (*f)(tid, "R12", vex->guest_R12); |
| 278 | (*f)(tid, "R13", vex->guest_R13); |
| 279 | (*f)(tid, "R14", vex->guest_R14); |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 280 | #elif defined(VGA_s390x) |
philippe | a22f59d | 2012-01-26 23:13:52 +0000 | [diff] [blame] | 281 | (*f)(tid, "r0" , vex->guest_r0 ); |
| 282 | (*f)(tid, "r1" , vex->guest_r1 ); |
| 283 | (*f)(tid, "r2" , vex->guest_r2 ); |
| 284 | (*f)(tid, "r3" , vex->guest_r3 ); |
| 285 | (*f)(tid, "r4" , vex->guest_r4 ); |
| 286 | (*f)(tid, "r5" , vex->guest_r5 ); |
| 287 | (*f)(tid, "r6" , vex->guest_r6 ); |
| 288 | (*f)(tid, "r7" , vex->guest_r7 ); |
| 289 | (*f)(tid, "r8" , vex->guest_r8 ); |
| 290 | (*f)(tid, "r9" , vex->guest_r9 ); |
| 291 | (*f)(tid, "r10", vex->guest_r10); |
| 292 | (*f)(tid, "r11", vex->guest_r11); |
| 293 | (*f)(tid, "r12", vex->guest_r12); |
| 294 | (*f)(tid, "r13", vex->guest_r13); |
| 295 | (*f)(tid, "r14", vex->guest_r14); |
| 296 | (*f)(tid, "r15", vex->guest_r15); |
sewardj | 5db1540 | 2012-06-07 09:13:21 +0000 | [diff] [blame] | 297 | #elif defined(VGA_mips32) |
| 298 | (*f)(tid, "r0" , vex->guest_r0 ); |
| 299 | (*f)(tid, "r1" , vex->guest_r1 ); |
| 300 | (*f)(tid, "r2" , vex->guest_r2 ); |
| 301 | (*f)(tid, "r3" , vex->guest_r3 ); |
| 302 | (*f)(tid, "r4" , vex->guest_r4 ); |
| 303 | (*f)(tid, "r5" , vex->guest_r5 ); |
| 304 | (*f)(tid, "r6" , vex->guest_r6 ); |
| 305 | (*f)(tid, "r7" , vex->guest_r7 ); |
| 306 | (*f)(tid, "r8" , vex->guest_r8 ); |
| 307 | (*f)(tid, "r9" , vex->guest_r9 ); |
| 308 | (*f)(tid, "r10", vex->guest_r10); |
| 309 | (*f)(tid, "r11", vex->guest_r11); |
| 310 | (*f)(tid, "r12", vex->guest_r12); |
| 311 | (*f)(tid, "r13", vex->guest_r13); |
| 312 | (*f)(tid, "r14", vex->guest_r14); |
| 313 | (*f)(tid, "r15", vex->guest_r15); |
| 314 | (*f)(tid, "r16", vex->guest_r16); |
| 315 | (*f)(tid, "r17", vex->guest_r17); |
| 316 | (*f)(tid, "r18", vex->guest_r18); |
| 317 | (*f)(tid, "r19", vex->guest_r19); |
| 318 | (*f)(tid, "r20", vex->guest_r20); |
| 319 | (*f)(tid, "r21", vex->guest_r21); |
| 320 | (*f)(tid, "r22", vex->guest_r22); |
| 321 | (*f)(tid, "r23", vex->guest_r23); |
| 322 | (*f)(tid, "r24", vex->guest_r24); |
| 323 | (*f)(tid, "r25", vex->guest_r25); |
| 324 | (*f)(tid, "r26", vex->guest_r26); |
| 325 | (*f)(tid, "r27", vex->guest_r27); |
| 326 | (*f)(tid, "r28", vex->guest_r28); |
| 327 | (*f)(tid, "r29", vex->guest_r29); |
| 328 | (*f)(tid, "r30", vex->guest_r30); |
| 329 | (*f)(tid, "r31", vex->guest_r31); |
njn | 6ace3ea | 2005-06-17 03:06:27 +0000 | [diff] [blame] | 330 | #else |
| 331 | # error Unknown arch |
| 332 | #endif |
| 333 | } |
| 334 | |
| 335 | |
philippe | a22f59d | 2012-01-26 23:13:52 +0000 | [diff] [blame] | 336 | void VG_(apply_to_GP_regs)(void (*f)(ThreadId, HChar*, UWord)) |
njn | 6ace3ea | 2005-06-17 03:06:27 +0000 | [diff] [blame] | 337 | { |
| 338 | ThreadId tid; |
| 339 | |
| 340 | for (tid = 1; tid < VG_N_THREADS; tid++) { |
| 341 | if (VG_(is_valid_tid)(tid)) { |
philippe | a22f59d | 2012-01-26 23:13:52 +0000 | [diff] [blame] | 342 | apply_to_GPs_of_tid(tid, f); |
njn | 6ace3ea | 2005-06-17 03:06:27 +0000 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | } |
| 346 | |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 347 | void VG_(thread_stack_reset_iter)(/*OUT*/ThreadId* tid) |
njn | b506bd8 | 2005-06-21 04:01:51 +0000 | [diff] [blame] | 348 | { |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 349 | *tid = (ThreadId)(-1); |
njn | b506bd8 | 2005-06-21 04:01:51 +0000 | [diff] [blame] | 350 | } |
njn | 6ace3ea | 2005-06-17 03:06:27 +0000 | [diff] [blame] | 351 | |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 352 | Bool VG_(thread_stack_next)(/*MOD*/ThreadId* tid, |
| 353 | /*OUT*/Addr* stack_min, |
| 354 | /*OUT*/Addr* stack_max) |
njn | 1d0cb0d | 2005-08-15 01:52:02 +0000 | [diff] [blame] | 355 | { |
| 356 | ThreadId i; |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 357 | for (i = (*tid)+1; i < VG_N_THREADS; i++) { |
| 358 | if (i == VG_INVALID_THREADID) |
| 359 | continue; |
njn | 1d0cb0d | 2005-08-15 01:52:02 +0000 | [diff] [blame] | 360 | if (VG_(threads)[i].status != VgTs_Empty) { |
| 361 | *tid = i; |
| 362 | *stack_min = VG_(get_SP)(i); |
| 363 | *stack_max = VG_(threads)[i].client_stack_highest_word; |
njn | 1d0cb0d | 2005-08-15 01:52:02 +0000 | [diff] [blame] | 364 | return True; |
| 365 | } |
| 366 | } |
| 367 | return False; |
| 368 | } |
sewardj | 7821e2e | 2005-08-08 00:35:46 +0000 | [diff] [blame] | 369 | |
sewardj | bbec772 | 2007-11-25 14:08:53 +0000 | [diff] [blame] | 370 | Addr VG_(thread_get_stack_max)(ThreadId tid) |
| 371 | { |
| 372 | vg_assert(0 <= tid && tid < VG_N_THREADS && tid != VG_INVALID_THREADID); |
| 373 | vg_assert(VG_(threads)[tid].status != VgTs_Empty); |
| 374 | return VG_(threads)[tid].client_stack_highest_word; |
| 375 | } |
| 376 | |
bart | 0fb0320 | 2008-03-29 09:25:53 +0000 | [diff] [blame] | 377 | SizeT VG_(thread_get_stack_size)(ThreadId tid) |
| 378 | { |
| 379 | vg_assert(0 <= tid && tid < VG_N_THREADS && tid != VG_INVALID_THREADID); |
| 380 | vg_assert(VG_(threads)[tid].status != VgTs_Empty); |
| 381 | return VG_(threads)[tid].client_stack_szB; |
| 382 | } |
| 383 | |
bart | 83c5a92 | 2010-09-02 14:38:38 +0000 | [diff] [blame] | 384 | Addr VG_(thread_get_altstack_min)(ThreadId tid) |
| 385 | { |
| 386 | vg_assert(0 <= tid && tid < VG_N_THREADS && tid != VG_INVALID_THREADID); |
| 387 | vg_assert(VG_(threads)[tid].status != VgTs_Empty); |
| 388 | return (Addr)VG_(threads)[tid].altstack.ss_sp; |
| 389 | } |
| 390 | |
| 391 | SizeT VG_(thread_get_altstack_size)(ThreadId tid) |
| 392 | { |
| 393 | vg_assert(0 <= tid && tid < VG_N_THREADS && tid != VG_INVALID_THREADID); |
| 394 | vg_assert(VG_(threads)[tid].status != VgTs_Empty); |
| 395 | return VG_(threads)[tid].altstack.ss_size; |
| 396 | } |
| 397 | |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 398 | //------------------------------------------------------------- |
| 399 | /* Details about the capabilities of the underlying (host) CPU. These |
| 400 | details are acquired by (1) enquiring with the CPU at startup, or |
| 401 | (2) from the AT_SYSINFO entries the kernel gave us (ppc32 cache |
| 402 | line size). It's a bit nasty in the sense that there's no obvious |
| 403 | way to stop uses of some of this info before it's ready to go. |
florian | 0daa4e3 | 2012-04-22 02:48:20 +0000 | [diff] [blame] | 404 | See pub_core_machine.h for more information about that. |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 405 | |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 406 | VG_(machine_get_hwcaps) may use signals (although it attempts to |
| 407 | leave signal state unchanged) and therefore should only be |
| 408 | called before m_main sets up the client's signal state. |
| 409 | */ |
| 410 | |
| 411 | /* --------- State --------- */ |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 412 | static Bool hwcaps_done = False; |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 413 | |
| 414 | /* --- all archs --- */ |
sewardj | 98763d5 | 2012-06-03 22:40:07 +0000 | [diff] [blame] | 415 | static VexArch va = VexArch_INVALID; |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 416 | static VexArchInfo vai; |
sewardj | a48a493 | 2005-09-29 11:09:56 +0000 | [diff] [blame] | 417 | |
sewardj | 7821e2e | 2005-08-08 00:35:46 +0000 | [diff] [blame] | 418 | #if defined(VGA_x86) |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 419 | UInt VG_(machine_x86_have_mxcsr) = 0; |
sewardj | 7821e2e | 2005-08-08 00:35:46 +0000 | [diff] [blame] | 420 | #endif |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 421 | #if defined(VGA_ppc32) |
sewardj | 2c36d42 | 2005-11-13 01:59:22 +0000 | [diff] [blame] | 422 | UInt VG_(machine_ppc32_has_FP) = 0; |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 423 | UInt VG_(machine_ppc32_has_VMX) = 0; |
| 424 | #endif |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 425 | #if defined(VGA_ppc64) |
| 426 | ULong VG_(machine_ppc64_has_VMX) = 0; |
| 427 | #endif |
sewardj | 1dbd337 | 2010-08-22 12:21:14 +0000 | [diff] [blame] | 428 | #if defined(VGA_arm) |
| 429 | Int VG_(machine_arm_archlevel) = 4; |
| 430 | #endif |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 431 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 432 | /* fixs390: anything for s390x here ? */ |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 433 | |
sewardj | 2c3f2ea | 2011-04-13 15:40:10 +0000 | [diff] [blame] | 434 | /* For hwcaps detection on ppc32/64, s390x, and arm we'll need to do SIGILL |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 435 | testing, so we need a VG_MINIMAL_JMP_BUF. */ |
| 436 | #if defined(VGA_ppc32) || defined(VGA_ppc64) \ |
petarj | 2fd883a | 2012-06-30 02:12:13 +0000 | [diff] [blame] | 437 | || defined(VGA_arm) || defined(VGA_s390x) |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 438 | #include "pub_tool_libcsetjmp.h" |
sewardj | 97d3ebb | 2011-04-11 18:36:34 +0000 | [diff] [blame] | 439 | static VG_MINIMAL_JMP_BUF(env_unsup_insn); |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 440 | static void handler_unsup_insn ( Int x ) { |
| 441 | VG_MINIMAL_LONGJMP(env_unsup_insn); |
| 442 | } |
sewardj | 5ae70ce | 2010-09-08 15:12:33 +0000 | [diff] [blame] | 443 | #endif |
| 444 | |
sewardj | b9c815b | 2010-09-03 15:51:34 +0000 | [diff] [blame] | 445 | |
| 446 | /* Helper function for VG_(machine_get_hwcaps), assumes the SIGILL/etc |
| 447 | * handlers are installed. Determines the the sizes affected by dcbz |
| 448 | * and dcbzl instructions and updates the given VexArchInfo structure |
| 449 | * accordingly. |
| 450 | * |
| 451 | * Not very defensive: assumes that as long as the dcbz/dcbzl |
| 452 | * instructions don't raise a SIGILL, that they will zero an aligned, |
| 453 | * contiguous block of memory of a sensible size. */ |
sewardj | 5ae70ce | 2010-09-08 15:12:33 +0000 | [diff] [blame] | 454 | #if defined(VGA_ppc32) || defined(VGA_ppc64) |
sewardj | b9c815b | 2010-09-03 15:51:34 +0000 | [diff] [blame] | 455 | static void find_ppc_dcbz_sz(VexArchInfo *arch_info) |
| 456 | { |
sewardj | dcb3a59 | 2010-09-04 00:43:14 +0000 | [diff] [blame] | 457 | Int dcbz_szB = 0; |
sewardj | b9c815b | 2010-09-03 15:51:34 +0000 | [diff] [blame] | 458 | Int dcbzl_szB; |
sewardj | 5ae70ce | 2010-09-08 15:12:33 +0000 | [diff] [blame] | 459 | # define MAX_DCBZL_SZB (128) /* largest known effect of dcbzl */ |
sewardj | b9c815b | 2010-09-03 15:51:34 +0000 | [diff] [blame] | 460 | char test_block[4*MAX_DCBZL_SZB]; |
| 461 | char *aligned = test_block; |
| 462 | Int i; |
| 463 | |
| 464 | /* round up to next max block size, assumes MAX_DCBZL_SZB is pof2 */ |
| 465 | aligned = (char *)(((HWord)aligned + MAX_DCBZL_SZB) & ~(MAX_DCBZL_SZB - 1)); |
| 466 | vg_assert((aligned + MAX_DCBZL_SZB) <= &test_block[sizeof(test_block)]); |
| 467 | |
| 468 | /* dcbz often clears 32B, although sometimes whatever the native cache |
| 469 | * block size is */ |
| 470 | VG_(memset)(test_block, 0xff, sizeof(test_block)); |
| 471 | __asm__ __volatile__("dcbz 0,%0" |
| 472 | : /*out*/ |
| 473 | : "r" (aligned) /*in*/ |
| 474 | : "memory" /*clobber*/); |
| 475 | for (dcbz_szB = 0, i = 0; i < sizeof(test_block); ++i) { |
| 476 | if (!test_block[i]) |
| 477 | ++dcbz_szB; |
| 478 | } |
| 479 | vg_assert(dcbz_szB == 32 || dcbz_szB == 64 || dcbz_szB == 128); |
| 480 | |
| 481 | /* dcbzl clears 128B on G5/PPC970, and usually 32B on other platforms */ |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 482 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
sewardj | b9c815b | 2010-09-03 15:51:34 +0000 | [diff] [blame] | 483 | dcbzl_szB = 0; /* indicates unsupported */ |
| 484 | } |
| 485 | else { |
| 486 | VG_(memset)(test_block, 0xff, sizeof(test_block)); |
| 487 | /* some older assemblers won't understand the dcbzl instruction |
| 488 | * variant, so we directly emit the instruction ourselves */ |
| 489 | __asm__ __volatile__("mr 9, %0 ; .long 0x7C204FEC" /*dcbzl 0,9*/ |
| 490 | : /*out*/ |
| 491 | : "r" (aligned) /*in*/ |
| 492 | : "memory", "r9" /*clobber*/); |
| 493 | for (dcbzl_szB = 0, i = 0; i < sizeof(test_block); ++i) { |
| 494 | if (!test_block[i]) |
| 495 | ++dcbzl_szB; |
| 496 | } |
| 497 | vg_assert(dcbzl_szB == 32 || dcbzl_szB == 64 || dcbzl_szB == 128); |
| 498 | } |
| 499 | |
| 500 | arch_info->ppc_dcbz_szB = dcbz_szB; |
| 501 | arch_info->ppc_dcbzl_szB = dcbzl_szB; |
| 502 | |
| 503 | VG_(debugLog)(1, "machine", "dcbz_szB=%d dcbzl_szB=%d\n", |
| 504 | dcbz_szB, dcbzl_szB); |
sewardj | 5ae70ce | 2010-09-08 15:12:33 +0000 | [diff] [blame] | 505 | # undef MAX_DCBZL_SZB |
sewardj | b9c815b | 2010-09-03 15:51:34 +0000 | [diff] [blame] | 506 | } |
sewardj | 5ae70ce | 2010-09-08 15:12:33 +0000 | [diff] [blame] | 507 | #endif /* defined(VGA_ppc32) || defined(VGA_ppc64) */ |
| 508 | |
sewardj | 2c3f2ea | 2011-04-13 15:40:10 +0000 | [diff] [blame] | 509 | #ifdef VGA_s390x |
sewardj | 5ae70ce | 2010-09-08 15:12:33 +0000 | [diff] [blame] | 510 | |
sewardj | 2c3f2ea | 2011-04-13 15:40:10 +0000 | [diff] [blame] | 511 | /* Read /proc/cpuinfo. Look for lines like these |
| 512 | |
| 513 | processor 0: version = FF, identification = 0117C9, machine = 2064 |
| 514 | |
florian | 4e63b8e | 2012-04-22 03:50:20 +0000 | [diff] [blame] | 515 | and return the machine model. If the machine model could not be determined |
| 516 | or it is an unknown model, return VEX_S390X_MODEL_UNKNOWN. */ |
sewardj | 2c3f2ea | 2011-04-13 15:40:10 +0000 | [diff] [blame] | 517 | |
| 518 | static UInt VG_(get_machine_model)(void) |
| 519 | { |
| 520 | static struct model_map { |
| 521 | HChar name[5]; |
| 522 | UInt id; |
| 523 | } model_map[] = { |
| 524 | { "2064", VEX_S390X_MODEL_Z900 }, |
| 525 | { "2066", VEX_S390X_MODEL_Z800 }, |
| 526 | { "2084", VEX_S390X_MODEL_Z990 }, |
| 527 | { "2086", VEX_S390X_MODEL_Z890 }, |
| 528 | { "2094", VEX_S390X_MODEL_Z9_EC }, |
| 529 | { "2096", VEX_S390X_MODEL_Z9_BC }, |
| 530 | { "2097", VEX_S390X_MODEL_Z10_EC }, |
| 531 | { "2098", VEX_S390X_MODEL_Z10_BC }, |
| 532 | { "2817", VEX_S390X_MODEL_Z196 }, |
florian | 258ede7 | 2011-09-02 22:20:41 +0000 | [diff] [blame] | 533 | { "2818", VEX_S390X_MODEL_Z114 }, |
florian | 87a25cf | 2012-08-28 13:33:10 +0000 | [diff] [blame] | 534 | { "2827", VEX_S390X_MODEL_ZEC12 }, |
sewardj | 2c3f2ea | 2011-04-13 15:40:10 +0000 | [diff] [blame] | 535 | }; |
| 536 | |
| 537 | Int model, n, fh; |
| 538 | SysRes fd; |
| 539 | SizeT num_bytes, file_buf_size; |
| 540 | HChar *p, *m, *model_name, *file_buf; |
| 541 | |
| 542 | /* Slurp contents of /proc/cpuinfo into FILE_BUF */ |
| 543 | fd = VG_(open)( "/proc/cpuinfo", 0, VKI_S_IRUSR ); |
florian | 4e63b8e | 2012-04-22 03:50:20 +0000 | [diff] [blame] | 544 | if ( sr_isError(fd) ) return VEX_S390X_MODEL_UNKNOWN; |
sewardj | 2c3f2ea | 2011-04-13 15:40:10 +0000 | [diff] [blame] | 545 | |
| 546 | fh = sr_Res(fd); |
| 547 | |
| 548 | /* Determine the size of /proc/cpuinfo. |
| 549 | Work around broken-ness in /proc file system implementation. |
| 550 | fstat returns a zero size for /proc/cpuinfo although it is |
| 551 | claimed to be a regular file. */ |
| 552 | num_bytes = 0; |
| 553 | file_buf_size = 1000; |
| 554 | file_buf = VG_(malloc)("cpuinfo", file_buf_size + 1); |
| 555 | while (42) { |
| 556 | n = VG_(read)(fh, file_buf, file_buf_size); |
| 557 | if (n < 0) break; |
| 558 | |
| 559 | num_bytes += n; |
| 560 | if (n < file_buf_size) break; /* reached EOF */ |
| 561 | } |
| 562 | |
| 563 | if (n < 0) num_bytes = 0; /* read error; ignore contents */ |
| 564 | |
| 565 | if (num_bytes > file_buf_size) { |
| 566 | VG_(free)( file_buf ); |
| 567 | VG_(lseek)( fh, 0, VKI_SEEK_SET ); |
| 568 | file_buf = VG_(malloc)( "cpuinfo", num_bytes + 1 ); |
| 569 | n = VG_(read)( fh, file_buf, num_bytes ); |
| 570 | if (n < 0) num_bytes = 0; |
| 571 | } |
| 572 | |
| 573 | file_buf[num_bytes] = '\0'; |
| 574 | VG_(close)(fh); |
| 575 | |
| 576 | /* Parse file */ |
florian | 4e63b8e | 2012-04-22 03:50:20 +0000 | [diff] [blame] | 577 | model = VEX_S390X_MODEL_UNKNOWN; |
sewardj | 2c3f2ea | 2011-04-13 15:40:10 +0000 | [diff] [blame] | 578 | for (p = file_buf; *p; ++p) { |
| 579 | /* Beginning of line */ |
| 580 | if (VG_(strncmp)( p, "processor", sizeof "processor" - 1 ) != 0) continue; |
| 581 | |
| 582 | m = VG_(strstr)( p, "machine" ); |
| 583 | if (m == NULL) continue; |
| 584 | |
| 585 | p = m + sizeof "machine" - 1; |
| 586 | while ( VG_(isspace)( *p ) || *p == '=') { |
| 587 | if (*p == '\n') goto next_line; |
| 588 | ++p; |
| 589 | } |
| 590 | |
| 591 | model_name = p; |
| 592 | for (n = 0; n < sizeof model_map / sizeof model_map[0]; ++n) { |
| 593 | struct model_map *mm = model_map + n; |
| 594 | SizeT len = VG_(strlen)( mm->name ); |
| 595 | if ( VG_(strncmp)( mm->name, model_name, len ) == 0 && |
| 596 | VG_(isspace)( model_name[len] )) { |
| 597 | if (mm->id < model) model = mm->id; |
| 598 | p = model_name + len; |
| 599 | break; |
| 600 | } |
| 601 | } |
| 602 | /* Skip until end-of-line */ |
| 603 | while (*p != '\n') |
| 604 | ++p; |
| 605 | next_line: ; |
| 606 | } |
| 607 | |
| 608 | VG_(free)( file_buf ); |
florian | 0016492 | 2011-10-25 21:37:15 +0000 | [diff] [blame] | 609 | VG_(debugLog)(1, "machine", "model = %s\n", |
florian | 4e63b8e | 2012-04-22 03:50:20 +0000 | [diff] [blame] | 610 | model == VEX_S390X_MODEL_UNKNOWN ? "UNKNOWN" |
florian | 0016492 | 2011-10-25 21:37:15 +0000 | [diff] [blame] | 611 | : model_map[model].name); |
sewardj | 2c3f2ea | 2011-04-13 15:40:10 +0000 | [diff] [blame] | 612 | return model; |
| 613 | } |
| 614 | |
| 615 | #endif /* VGA_s390x */ |
sewardj | 5ae70ce | 2010-09-08 15:12:33 +0000 | [diff] [blame] | 616 | |
sewardj | 5db1540 | 2012-06-07 09:13:21 +0000 | [diff] [blame] | 617 | #ifdef VGA_mips32 |
| 618 | |
| 619 | /* Read /proc/cpuinfo and return the machine model. */ |
| 620 | static UInt VG_(get_machine_model)(void) |
| 621 | { |
| 622 | char *search_MIPS_str = "MIPS"; |
| 623 | char *search_Broadcom_str = "Broadcom"; |
| 624 | Int n, fh; |
| 625 | SysRes fd; |
| 626 | SizeT num_bytes, file_buf_size; |
| 627 | HChar *file_buf; |
| 628 | |
| 629 | /* Slurp contents of /proc/cpuinfo into FILE_BUF */ |
| 630 | fd = VG_(open)( "/proc/cpuinfo", 0, VKI_S_IRUSR ); |
| 631 | if ( sr_isError(fd) ) return -1; |
| 632 | |
| 633 | fh = sr_Res(fd); |
| 634 | |
| 635 | /* Determine the size of /proc/cpuinfo. |
| 636 | Work around broken-ness in /proc file system implementation. |
| 637 | fstat returns a zero size for /proc/cpuinfo although it is |
| 638 | claimed to be a regular file. */ |
| 639 | num_bytes = 0; |
| 640 | file_buf_size = 1000; |
| 641 | file_buf = VG_(malloc)("cpuinfo", file_buf_size + 1); |
| 642 | while (42) { |
| 643 | n = VG_(read)(fh, file_buf, file_buf_size); |
| 644 | if (n < 0) break; |
| 645 | |
| 646 | num_bytes += n; |
| 647 | if (n < file_buf_size) break; /* reached EOF */ |
| 648 | } |
| 649 | |
| 650 | if (n < 0) num_bytes = 0; /* read error; ignore contents */ |
| 651 | |
| 652 | if (num_bytes > file_buf_size) { |
| 653 | VG_(free)( file_buf ); |
| 654 | VG_(lseek)( fh, 0, VKI_SEEK_SET ); |
| 655 | file_buf = VG_(malloc)( "cpuinfo", num_bytes + 1 ); |
| 656 | n = VG_(read)( fh, file_buf, num_bytes ); |
| 657 | if (n < 0) num_bytes = 0; |
| 658 | } |
| 659 | |
| 660 | file_buf[num_bytes] = '\0'; |
| 661 | VG_(close)(fh); |
| 662 | |
| 663 | /* Parse file */ |
| 664 | if (VG_(strstr) (file_buf, search_Broadcom_str) != NULL) |
| 665 | return VEX_PRID_COMP_BROADCOM; |
| 666 | if (VG_(strstr) (file_buf, search_MIPS_str) != NULL) |
| 667 | return VEX_PRID_COMP_MIPS; |
| 668 | |
| 669 | /* Did not find string in the proc file. */ |
| 670 | return -1; |
| 671 | } |
| 672 | |
| 673 | #endif |
| 674 | |
sewardj | 5ae70ce | 2010-09-08 15:12:33 +0000 | [diff] [blame] | 675 | /* Determine what insn set and insn set variant the host has, and |
| 676 | record it. To be called once at system startup. Returns False if |
florian | 7862701 | 2012-10-07 19:47:04 +0000 | [diff] [blame^] | 677 | this a CPU incapable of running Valgrind. |
| 678 | Also determine information about the caches on this host. */ |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 679 | |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 680 | Bool VG_(machine_get_hwcaps)( void ) |
| 681 | { |
| 682 | vg_assert(hwcaps_done == False); |
| 683 | hwcaps_done = True; |
| 684 | |
| 685 | // Whack default settings into vai, so that we only need to fill in |
| 686 | // any interesting bits. |
| 687 | LibVEX_default_VexArchInfo(&vai); |
| 688 | |
| 689 | #if defined(VGA_x86) |
sewardj | 40d91c7 | 2010-07-29 15:40:32 +0000 | [diff] [blame] | 690 | { Bool have_sse1, have_sse2, have_cx8, have_lzcnt; |
sewardj | c7ffc94 | 2011-03-28 16:26:42 +0000 | [diff] [blame] | 691 | UInt eax, ebx, ecx, edx, max_extended; |
sewardj | 40d91c7 | 2010-07-29 15:40:32 +0000 | [diff] [blame] | 692 | UChar vstr[13]; |
| 693 | vstr[0] = 0; |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 694 | |
| 695 | if (!VG_(has_cpuid)()) |
| 696 | /* we can't do cpuid at all. Give up. */ |
| 697 | return False; |
| 698 | |
tom | ad8a591 | 2011-06-10 15:04:22 +0000 | [diff] [blame] | 699 | VG_(cpuid)(0, 0, &eax, &ebx, &ecx, &edx); |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 700 | if (eax < 1) |
| 701 | /* we can't ask for cpuid(x) for x > 0. Give up. */ |
| 702 | return False; |
| 703 | |
sewardj | 40d91c7 | 2010-07-29 15:40:32 +0000 | [diff] [blame] | 704 | /* Get processor ID string, and max basic/extended index |
| 705 | values. */ |
sewardj | 40d91c7 | 2010-07-29 15:40:32 +0000 | [diff] [blame] | 706 | VG_(memcpy)(&vstr[0], &ebx, 4); |
| 707 | VG_(memcpy)(&vstr[4], &edx, 4); |
| 708 | VG_(memcpy)(&vstr[8], &ecx, 4); |
| 709 | vstr[12] = 0; |
| 710 | |
tom | ad8a591 | 2011-06-10 15:04:22 +0000 | [diff] [blame] | 711 | VG_(cpuid)(0x80000000, 0, &eax, &ebx, &ecx, &edx); |
sewardj | 40d91c7 | 2010-07-29 15:40:32 +0000 | [diff] [blame] | 712 | max_extended = eax; |
| 713 | |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 714 | /* get capabilities bits into edx */ |
tom | ad8a591 | 2011-06-10 15:04:22 +0000 | [diff] [blame] | 715 | VG_(cpuid)(1, 0, &eax, &ebx, &ecx, &edx); |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 716 | |
| 717 | have_sse1 = (edx & (1<<25)) != 0; /* True => have sse insns */ |
| 718 | have_sse2 = (edx & (1<<26)) != 0; /* True => have sse2 insns */ |
| 719 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 720 | /* cmpxchg8b is a minimum requirement now; if we don't have it we |
| 721 | must simply give up. But all CPUs since Pentium-I have it, so |
| 722 | that doesn't seem like much of a restriction. */ |
| 723 | have_cx8 = (edx & (1<<8)) != 0; /* True => have cmpxchg8b */ |
| 724 | if (!have_cx8) |
| 725 | return False; |
| 726 | |
sewardj | 40d91c7 | 2010-07-29 15:40:32 +0000 | [diff] [blame] | 727 | /* Figure out if this is an AMD that can do LZCNT. */ |
| 728 | have_lzcnt = False; |
| 729 | if (0 == VG_(strcmp)(vstr, "AuthenticAMD") |
| 730 | && max_extended >= 0x80000001) { |
tom | ad8a591 | 2011-06-10 15:04:22 +0000 | [diff] [blame] | 731 | VG_(cpuid)(0x80000001, 0, &eax, &ebx, &ecx, &edx); |
sewardj | 40d91c7 | 2010-07-29 15:40:32 +0000 | [diff] [blame] | 732 | have_lzcnt = (ecx & (1<<5)) != 0; /* True => have LZCNT */ |
| 733 | } |
| 734 | |
florian | 7862701 | 2012-10-07 19:47:04 +0000 | [diff] [blame^] | 735 | va = VexArchX86; |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 736 | if (have_sse2 && have_sse1) { |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 737 | vai.hwcaps = VEX_HWCAPS_X86_SSE1; |
| 738 | vai.hwcaps |= VEX_HWCAPS_X86_SSE2; |
sewardj | 40d91c7 | 2010-07-29 15:40:32 +0000 | [diff] [blame] | 739 | if (have_lzcnt) |
| 740 | vai.hwcaps |= VEX_HWCAPS_X86_LZCNT; |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 741 | VG_(machine_x86_have_mxcsr) = 1; |
florian | 7862701 | 2012-10-07 19:47:04 +0000 | [diff] [blame^] | 742 | } else if (have_sse1) { |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 743 | vai.hwcaps = VEX_HWCAPS_X86_SSE1; |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 744 | VG_(machine_x86_have_mxcsr) = 1; |
florian | 7862701 | 2012-10-07 19:47:04 +0000 | [diff] [blame^] | 745 | } else { |
| 746 | vai.hwcaps = 0; /*baseline - no sse at all*/ |
| 747 | VG_(machine_x86_have_mxcsr) = 0; |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 748 | } |
| 749 | |
florian | 7862701 | 2012-10-07 19:47:04 +0000 | [diff] [blame^] | 750 | VG_(machine_get_cache_info)(&vai); |
| 751 | |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 752 | return True; |
| 753 | } |
| 754 | |
| 755 | #elif defined(VGA_amd64) |
sewardj | c7ffc94 | 2011-03-28 16:26:42 +0000 | [diff] [blame] | 756 | { Bool have_sse3, have_cx8, have_cx16; |
sewardj | ee1a897 | 2012-04-26 14:17:50 +0000 | [diff] [blame] | 757 | Bool have_lzcnt, have_avx /*, have_fma*/; |
sewardj | c7ffc94 | 2011-03-28 16:26:42 +0000 | [diff] [blame] | 758 | UInt eax, ebx, ecx, edx, max_extended; |
sewardj | 40d91c7 | 2010-07-29 15:40:32 +0000 | [diff] [blame] | 759 | UChar vstr[13]; |
| 760 | vstr[0] = 0; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 761 | |
| 762 | if (!VG_(has_cpuid)()) |
| 763 | /* we can't do cpuid at all. Give up. */ |
| 764 | return False; |
| 765 | |
tom | ad8a591 | 2011-06-10 15:04:22 +0000 | [diff] [blame] | 766 | VG_(cpuid)(0, 0, &eax, &ebx, &ecx, &edx); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 767 | if (eax < 1) |
| 768 | /* we can't ask for cpuid(x) for x > 0. Give up. */ |
| 769 | return False; |
| 770 | |
sewardj | 40d91c7 | 2010-07-29 15:40:32 +0000 | [diff] [blame] | 771 | /* Get processor ID string, and max basic/extended index |
| 772 | values. */ |
sewardj | 40d91c7 | 2010-07-29 15:40:32 +0000 | [diff] [blame] | 773 | VG_(memcpy)(&vstr[0], &ebx, 4); |
| 774 | VG_(memcpy)(&vstr[4], &edx, 4); |
| 775 | VG_(memcpy)(&vstr[8], &ecx, 4); |
| 776 | vstr[12] = 0; |
| 777 | |
tom | ad8a591 | 2011-06-10 15:04:22 +0000 | [diff] [blame] | 778 | VG_(cpuid)(0x80000000, 0, &eax, &ebx, &ecx, &edx); |
sewardj | 40d91c7 | 2010-07-29 15:40:32 +0000 | [diff] [blame] | 779 | max_extended = eax; |
| 780 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 781 | /* get capabilities bits into edx */ |
tom | ad8a591 | 2011-06-10 15:04:22 +0000 | [diff] [blame] | 782 | VG_(cpuid)(1, 0, &eax, &ebx, &ecx, &edx); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 783 | |
sewardj | c7ffc94 | 2011-03-28 16:26:42 +0000 | [diff] [blame] | 784 | // we assume that SSE1 and SSE2 are available by default |
sewardj | 598971e | 2009-07-12 13:19:04 +0000 | [diff] [blame] | 785 | have_sse3 = (ecx & (1<<0)) != 0; /* True => have sse3 insns */ |
sewardj | ee1a897 | 2012-04-26 14:17:50 +0000 | [diff] [blame] | 786 | // ssse3 is ecx:9 |
| 787 | // sse41 is ecx:19 |
| 788 | // sse42 is ecx:20 |
| 789 | |
| 790 | // osxsave is ecx:27 |
| 791 | // avx is ecx:28 |
| 792 | // fma is ecx:12 |
| 793 | have_avx = False; |
| 794 | /* have_fma = False; */ |
| 795 | if ( (ecx & ((1<<27)|(1<<28))) == ((1<<27)|(1<<28)) ) { |
| 796 | /* processor supports AVX instructions and XGETBV is enabled |
| 797 | by OS */ |
| 798 | ULong w; |
| 799 | __asm__ __volatile__("movq $0,%%rcx ; " |
| 800 | ".byte 0x0F,0x01,0xD0 ; " /* xgetbv */ |
| 801 | "movq %%rax,%0" |
| 802 | :/*OUT*/"=r"(w) :/*IN*/ |
| 803 | :/*TRASH*/"rdx","rcx"); |
| 804 | if ((w & 6) == 6) { |
| 805 | /* OS has enabled both XMM and YMM state support */ |
| 806 | have_avx = True; |
| 807 | /* have_fma = (ecx & (1<<12)) != 0; */ |
| 808 | /* have_fma: Probably correct, but gcc complains due to |
| 809 | unusedness. &*/ |
| 810 | } |
| 811 | } |
| 812 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 813 | |
| 814 | /* cmpxchg8b is a minimum requirement now; if we don't have it we |
| 815 | must simply give up. But all CPUs since Pentium-I have it, so |
| 816 | that doesn't seem like much of a restriction. */ |
| 817 | have_cx8 = (edx & (1<<8)) != 0; /* True => have cmpxchg8b */ |
| 818 | if (!have_cx8) |
| 819 | return False; |
| 820 | |
| 821 | /* on amd64 we tolerate older cpus, which don't have cmpxchg16b */ |
| 822 | have_cx16 = (ecx & (1<<13)) != 0; /* True => have cmpxchg16b */ |
| 823 | |
sewardj | 40d91c7 | 2010-07-29 15:40:32 +0000 | [diff] [blame] | 824 | /* Figure out if this is an AMD that can do LZCNT. */ |
| 825 | have_lzcnt = False; |
| 826 | if (0 == VG_(strcmp)(vstr, "AuthenticAMD") |
| 827 | && max_extended >= 0x80000001) { |
tom | ad8a591 | 2011-06-10 15:04:22 +0000 | [diff] [blame] | 828 | VG_(cpuid)(0x80000001, 0, &eax, &ebx, &ecx, &edx); |
sewardj | 40d91c7 | 2010-07-29 15:40:32 +0000 | [diff] [blame] | 829 | have_lzcnt = (ecx & (1<<5)) != 0; /* True => have LZCNT */ |
| 830 | } |
| 831 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 832 | va = VexArchAMD64; |
sewardj | ee1a897 | 2012-04-26 14:17:50 +0000 | [diff] [blame] | 833 | vai.hwcaps = (have_sse3 ? VEX_HWCAPS_AMD64_SSE3 : 0) |
| 834 | | (have_cx16 ? VEX_HWCAPS_AMD64_CX16 : 0) |
| 835 | | (have_lzcnt ? VEX_HWCAPS_AMD64_LZCNT : 0) |
| 836 | | (have_avx ? VEX_HWCAPS_AMD64_AVX : 0); |
florian | 7862701 | 2012-10-07 19:47:04 +0000 | [diff] [blame^] | 837 | |
| 838 | VG_(machine_get_cache_info)(&vai); |
| 839 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 840 | return True; |
| 841 | } |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 842 | |
| 843 | #elif defined(VGA_ppc32) |
bart | 1581e74 | 2009-01-13 07:49:14 +0000 | [diff] [blame] | 844 | { |
| 845 | /* Find out which subset of the ppc32 instruction set is supported by |
| 846 | verifying whether various ppc32 instructions generate a SIGILL |
| 847 | or a SIGFPE. An alternative approach is to check the AT_HWCAP and |
| 848 | AT_PLATFORM entries in the ELF auxiliary table -- see also |
| 849 | the_iifii.client_auxv in m_main.c. |
| 850 | */ |
njn | cda2f0f | 2009-05-18 02:12:08 +0000 | [diff] [blame] | 851 | vki_sigset_t saved_set, tmp_set; |
| 852 | vki_sigaction_fromK_t saved_sigill_act, saved_sigfpe_act; |
| 853 | vki_sigaction_toK_t tmp_sigill_act, tmp_sigfpe_act; |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 854 | |
sewardj | 5ba075a | 2012-04-02 21:25:14 +0000 | [diff] [blame] | 855 | volatile Bool have_F, have_V, have_FX, have_GX, have_VX, have_DFP; |
sewardj | 7637e9e | 2006-02-21 17:11:11 +0000 | [diff] [blame] | 856 | Int r; |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 857 | |
njn | cda2f0f | 2009-05-18 02:12:08 +0000 | [diff] [blame] | 858 | /* This is a kludge. Really we ought to back-convert saved_act |
| 859 | into a toK_t using VG_(convert_sigaction_fromK_to_toK), but |
| 860 | since that's a no-op on all ppc32 platforms so far supported, |
| 861 | it's not worth the typing effort. At least include most basic |
| 862 | sanity check: */ |
| 863 | vg_assert(sizeof(vki_sigaction_fromK_t) == sizeof(vki_sigaction_toK_t)); |
| 864 | |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 865 | VG_(sigemptyset)(&tmp_set); |
| 866 | VG_(sigaddset)(&tmp_set, VKI_SIGILL); |
bart | 1581e74 | 2009-01-13 07:49:14 +0000 | [diff] [blame] | 867 | VG_(sigaddset)(&tmp_set, VKI_SIGFPE); |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 868 | |
sewardj | 7637e9e | 2006-02-21 17:11:11 +0000 | [diff] [blame] | 869 | r = VG_(sigprocmask)(VKI_SIG_UNBLOCK, &tmp_set, &saved_set); |
| 870 | vg_assert(r == 0); |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 871 | |
bart | 1581e74 | 2009-01-13 07:49:14 +0000 | [diff] [blame] | 872 | r = VG_(sigaction)(VKI_SIGILL, NULL, &saved_sigill_act); |
sewardj | 7637e9e | 2006-02-21 17:11:11 +0000 | [diff] [blame] | 873 | vg_assert(r == 0); |
bart | 1581e74 | 2009-01-13 07:49:14 +0000 | [diff] [blame] | 874 | tmp_sigill_act = saved_sigill_act; |
| 875 | |
| 876 | r = VG_(sigaction)(VKI_SIGFPE, NULL, &saved_sigfpe_act); |
| 877 | vg_assert(r == 0); |
| 878 | tmp_sigfpe_act = saved_sigfpe_act; |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 879 | |
sewardj | 7637e9e | 2006-02-21 17:11:11 +0000 | [diff] [blame] | 880 | /* NODEFER: signal handler does not return (from the kernel's point of |
| 881 | view), hence if it is to successfully catch a signal more than once, |
| 882 | we need the NODEFER flag. */ |
bart | 1581e74 | 2009-01-13 07:49:14 +0000 | [diff] [blame] | 883 | tmp_sigill_act.sa_flags &= ~VKI_SA_RESETHAND; |
| 884 | tmp_sigill_act.sa_flags &= ~VKI_SA_SIGINFO; |
| 885 | tmp_sigill_act.sa_flags |= VKI_SA_NODEFER; |
| 886 | tmp_sigill_act.ksa_handler = handler_unsup_insn; |
| 887 | r = VG_(sigaction)(VKI_SIGILL, &tmp_sigill_act, NULL); |
| 888 | vg_assert(r == 0); |
| 889 | |
| 890 | tmp_sigfpe_act.sa_flags &= ~VKI_SA_RESETHAND; |
| 891 | tmp_sigfpe_act.sa_flags &= ~VKI_SA_SIGINFO; |
| 892 | tmp_sigfpe_act.sa_flags |= VKI_SA_NODEFER; |
| 893 | tmp_sigfpe_act.ksa_handler = handler_unsup_insn; |
| 894 | r = VG_(sigaction)(VKI_SIGFPE, &tmp_sigfpe_act, NULL); |
| 895 | vg_assert(r == 0); |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 896 | |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 897 | /* standard FP insns */ |
| 898 | have_F = True; |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 899 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 900 | have_F = False; |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 901 | } else { |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 902 | __asm__ __volatile__(".long 0xFC000090"); /*fmr 0,0 */ |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 903 | } |
| 904 | |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 905 | /* Altivec insns */ |
| 906 | have_V = True; |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 907 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 908 | have_V = False; |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 909 | } else { |
sewardj | 7159212 | 2006-04-04 03:29:48 +0000 | [diff] [blame] | 910 | /* Unfortunately some older assemblers don't speak Altivec (or |
| 911 | choose not to), so to be safe we directly emit the 32-bit |
| 912 | word corresponding to "vor 0,0,0". This fixes a build |
| 913 | problem that happens on Debian 3.1 (ppc32), and probably |
| 914 | various other places. */ |
sewardj | 54d0dc7 | 2006-04-04 03:08:49 +0000 | [diff] [blame] | 915 | __asm__ __volatile__(".long 0x10000484"); /*vor 0,0,0*/ |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 916 | } |
| 917 | |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 918 | /* General-Purpose optional (fsqrt, fsqrts) */ |
| 919 | have_FX = True; |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 920 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 921 | have_FX = False; |
| 922 | } else { |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 923 | __asm__ __volatile__(".long 0xFC00002C"); /*fsqrt 0,0 */ |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | /* Graphics optional (stfiwx, fres, frsqrte, fsel) */ |
| 927 | have_GX = True; |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 928 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 929 | have_GX = False; |
| 930 | } else { |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 931 | __asm__ __volatile__(".long 0xFC000034"); /* frsqrte 0,0 */ |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 932 | } |
| 933 | |
sewardj | f34eb49 | 2011-04-15 11:57:05 +0000 | [diff] [blame] | 934 | /* VSX support implies Power ISA 2.06 */ |
| 935 | have_VX = True; |
| 936 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
| 937 | have_VX = False; |
| 938 | } else { |
| 939 | __asm__ __volatile__(".long 0xf0000564"); /* xsabsdp XT,XB */ |
| 940 | } |
| 941 | |
sewardj | 5ba075a | 2012-04-02 21:25:14 +0000 | [diff] [blame] | 942 | /* Check for Decimal Floating Point (DFP) support. */ |
| 943 | have_DFP = True; |
| 944 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
| 945 | have_DFP = False; |
| 946 | } else { |
| 947 | __asm__ __volatile__(".long 0xee4e8005"); /* dadd FRT,FRA, FRB */ |
| 948 | } |
sewardj | f34eb49 | 2011-04-15 11:57:05 +0000 | [diff] [blame] | 949 | |
sewardj | b9c815b | 2010-09-03 15:51:34 +0000 | [diff] [blame] | 950 | /* determine dcbz/dcbzl sizes while we still have the signal |
| 951 | * handlers registered */ |
| 952 | find_ppc_dcbz_sz(&vai); |
| 953 | |
bart | 1581e74 | 2009-01-13 07:49:14 +0000 | [diff] [blame] | 954 | r = VG_(sigaction)(VKI_SIGILL, &saved_sigill_act, NULL); |
| 955 | vg_assert(r == 0); |
| 956 | r = VG_(sigaction)(VKI_SIGFPE, &saved_sigfpe_act, NULL); |
sewardj | 7637e9e | 2006-02-21 17:11:11 +0000 | [diff] [blame] | 957 | vg_assert(r == 0); |
| 958 | r = VG_(sigprocmask)(VKI_SIG_SETMASK, &saved_set, NULL); |
| 959 | vg_assert(r == 0); |
sewardj | 5ba075a | 2012-04-02 21:25:14 +0000 | [diff] [blame] | 960 | VG_(debugLog)(1, "machine", "F %d V %d FX %d GX %d VX %d DFP %d\n", |
sewardj | f34eb49 | 2011-04-15 11:57:05 +0000 | [diff] [blame] | 961 | (Int)have_F, (Int)have_V, (Int)have_FX, |
sewardj | 5ba075a | 2012-04-02 21:25:14 +0000 | [diff] [blame] | 962 | (Int)have_GX, (Int)have_VX, (Int)have_DFP); |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 963 | /* Make FP a prerequisite for VMX (bogusly so), and for FX and GX. */ |
| 964 | if (have_V && !have_F) |
| 965 | have_V = False; |
| 966 | if (have_FX && !have_F) |
| 967 | have_FX = False; |
| 968 | if (have_GX && !have_F) |
| 969 | have_GX = False; |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 970 | |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 971 | VG_(machine_ppc32_has_FP) = have_F ? 1 : 0; |
| 972 | VG_(machine_ppc32_has_VMX) = have_V ? 1 : 0; |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 973 | |
| 974 | va = VexArchPPC32; |
| 975 | |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 976 | vai.hwcaps = 0; |
| 977 | if (have_F) vai.hwcaps |= VEX_HWCAPS_PPC32_F; |
| 978 | if (have_V) vai.hwcaps |= VEX_HWCAPS_PPC32_V; |
| 979 | if (have_FX) vai.hwcaps |= VEX_HWCAPS_PPC32_FX; |
| 980 | if (have_GX) vai.hwcaps |= VEX_HWCAPS_PPC32_GX; |
sewardj | f34eb49 | 2011-04-15 11:57:05 +0000 | [diff] [blame] | 981 | if (have_VX) vai.hwcaps |= VEX_HWCAPS_PPC32_VX; |
sewardj | 5ba075a | 2012-04-02 21:25:14 +0000 | [diff] [blame] | 982 | if (have_DFP) vai.hwcaps |= VEX_HWCAPS_PPC32_DFP; |
| 983 | |
florian | 7862701 | 2012-10-07 19:47:04 +0000 | [diff] [blame^] | 984 | VG_(machine_get_cache_info)(&vai); |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 985 | |
| 986 | /* But we're not done yet: VG_(machine_ppc32_set_clszB) must be |
| 987 | called before we're ready to go. */ |
| 988 | return True; |
| 989 | } |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 990 | |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 991 | #elif defined(VGA_ppc64) |
bart | 1581e74 | 2009-01-13 07:49:14 +0000 | [diff] [blame] | 992 | { |
| 993 | /* Same instruction set detection algorithm as for ppc32. */ |
njn | cda2f0f | 2009-05-18 02:12:08 +0000 | [diff] [blame] | 994 | vki_sigset_t saved_set, tmp_set; |
| 995 | vki_sigaction_fromK_t saved_sigill_act, saved_sigfpe_act; |
| 996 | vki_sigaction_toK_t tmp_sigill_act, tmp_sigfpe_act; |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 997 | |
sewardj | 5ba075a | 2012-04-02 21:25:14 +0000 | [diff] [blame] | 998 | volatile Bool have_F, have_V, have_FX, have_GX, have_VX, have_DFP; |
njn | cda2f0f | 2009-05-18 02:12:08 +0000 | [diff] [blame] | 999 | Int r; |
| 1000 | |
| 1001 | /* This is a kludge. Really we ought to back-convert saved_act |
| 1002 | into a toK_t using VG_(convert_sigaction_fromK_to_toK), but |
| 1003 | since that's a no-op on all ppc64 platforms so far supported, |
| 1004 | it's not worth the typing effort. At least include most basic |
| 1005 | sanity check: */ |
| 1006 | vg_assert(sizeof(vki_sigaction_fromK_t) == sizeof(vki_sigaction_toK_t)); |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 1007 | |
| 1008 | VG_(sigemptyset)(&tmp_set); |
| 1009 | VG_(sigaddset)(&tmp_set, VKI_SIGILL); |
bart | 1581e74 | 2009-01-13 07:49:14 +0000 | [diff] [blame] | 1010 | VG_(sigaddset)(&tmp_set, VKI_SIGFPE); |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 1011 | |
njn | cda2f0f | 2009-05-18 02:12:08 +0000 | [diff] [blame] | 1012 | r = VG_(sigprocmask)(VKI_SIG_UNBLOCK, &tmp_set, &saved_set); |
| 1013 | vg_assert(r == 0); |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 1014 | |
njn | cda2f0f | 2009-05-18 02:12:08 +0000 | [diff] [blame] | 1015 | r = VG_(sigaction)(VKI_SIGILL, NULL, &saved_sigill_act); |
| 1016 | vg_assert(r == 0); |
bart | 1581e74 | 2009-01-13 07:49:14 +0000 | [diff] [blame] | 1017 | tmp_sigill_act = saved_sigill_act; |
| 1018 | |
| 1019 | VG_(sigaction)(VKI_SIGFPE, NULL, &saved_sigfpe_act); |
| 1020 | tmp_sigfpe_act = saved_sigfpe_act; |
| 1021 | |
sewardj | 7637e9e | 2006-02-21 17:11:11 +0000 | [diff] [blame] | 1022 | /* NODEFER: signal handler does not return (from the kernel's point of |
| 1023 | view), hence if it is to successfully catch a signal more than once, |
| 1024 | we need the NODEFER flag. */ |
bart | 1581e74 | 2009-01-13 07:49:14 +0000 | [diff] [blame] | 1025 | tmp_sigill_act.sa_flags &= ~VKI_SA_RESETHAND; |
| 1026 | tmp_sigill_act.sa_flags &= ~VKI_SA_SIGINFO; |
| 1027 | tmp_sigill_act.sa_flags |= VKI_SA_NODEFER; |
| 1028 | tmp_sigill_act.ksa_handler = handler_unsup_insn; |
| 1029 | VG_(sigaction)(VKI_SIGILL, &tmp_sigill_act, NULL); |
| 1030 | |
| 1031 | tmp_sigfpe_act.sa_flags &= ~VKI_SA_RESETHAND; |
| 1032 | tmp_sigfpe_act.sa_flags &= ~VKI_SA_SIGINFO; |
| 1033 | tmp_sigfpe_act.sa_flags |= VKI_SA_NODEFER; |
| 1034 | tmp_sigfpe_act.ksa_handler = handler_unsup_insn; |
| 1035 | VG_(sigaction)(VKI_SIGFPE, &tmp_sigfpe_act, NULL); |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 1036 | |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 1037 | /* standard FP insns */ |
| 1038 | have_F = True; |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 1039 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 1040 | have_F = False; |
| 1041 | } else { |
| 1042 | __asm__ __volatile__("fmr 0,0"); |
| 1043 | } |
| 1044 | |
| 1045 | /* Altivec insns */ |
| 1046 | have_V = True; |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 1047 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 1048 | have_V = False; |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 1049 | } else { |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 1050 | __asm__ __volatile__(".long 0x10000484"); /*vor 0,0,0*/ |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 1051 | } |
| 1052 | |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 1053 | /* General-Purpose optional (fsqrt, fsqrts) */ |
| 1054 | have_FX = True; |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 1055 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 1056 | have_FX = False; |
| 1057 | } else { |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 1058 | __asm__ __volatile__(".long 0xFC00002C"); /*fsqrt 0,0*/ |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | /* Graphics optional (stfiwx, fres, frsqrte, fsel) */ |
| 1062 | have_GX = True; |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 1063 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 1064 | have_GX = False; |
| 1065 | } else { |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 1066 | __asm__ __volatile__(".long 0xFC000034"); /*frsqrte 0,0*/ |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
sewardj | f34eb49 | 2011-04-15 11:57:05 +0000 | [diff] [blame] | 1069 | /* VSX support implies Power ISA 2.06 */ |
| 1070 | have_VX = True; |
| 1071 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
| 1072 | have_VX = False; |
| 1073 | } else { |
| 1074 | __asm__ __volatile__(".long 0xf0000564"); /* xsabsdp XT,XB */ |
| 1075 | } |
| 1076 | |
sewardj | 5ba075a | 2012-04-02 21:25:14 +0000 | [diff] [blame] | 1077 | /* Check for Decimal Floating Point (DFP) support. */ |
| 1078 | have_DFP = True; |
| 1079 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
| 1080 | have_DFP = False; |
| 1081 | } else { |
| 1082 | __asm__ __volatile__(".long 0xee4e8005"); /* dadd FRT,FRA, FRB */ |
| 1083 | } |
| 1084 | |
sewardj | b9c815b | 2010-09-03 15:51:34 +0000 | [diff] [blame] | 1085 | /* determine dcbz/dcbzl sizes while we still have the signal |
| 1086 | * handlers registered */ |
| 1087 | find_ppc_dcbz_sz(&vai); |
| 1088 | |
bart | 1581e74 | 2009-01-13 07:49:14 +0000 | [diff] [blame] | 1089 | VG_(sigaction)(VKI_SIGILL, &saved_sigill_act, NULL); |
| 1090 | VG_(sigaction)(VKI_SIGFPE, &saved_sigfpe_act, NULL); |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 1091 | VG_(sigprocmask)(VKI_SIG_SETMASK, &saved_set, NULL); |
sewardj | 5ba075a | 2012-04-02 21:25:14 +0000 | [diff] [blame] | 1092 | VG_(debugLog)(1, "machine", "F %d V %d FX %d GX %d VX %d DFP %d\n", |
sewardj | f34eb49 | 2011-04-15 11:57:05 +0000 | [diff] [blame] | 1093 | (Int)have_F, (Int)have_V, (Int)have_FX, |
sewardj | 5ba075a | 2012-04-02 21:25:14 +0000 | [diff] [blame] | 1094 | (Int)have_GX, (Int)have_VX, (Int)have_DFP); |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 1095 | /* on ppc64, if we don't even have FP, just give up. */ |
| 1096 | if (!have_F) |
| 1097 | return False; |
| 1098 | |
| 1099 | VG_(machine_ppc64_has_VMX) = have_V ? 1 : 0; |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 1100 | |
| 1101 | va = VexArchPPC64; |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 1102 | |
| 1103 | vai.hwcaps = 0; |
| 1104 | if (have_V) vai.hwcaps |= VEX_HWCAPS_PPC64_V; |
| 1105 | if (have_FX) vai.hwcaps |= VEX_HWCAPS_PPC64_FX; |
| 1106 | if (have_GX) vai.hwcaps |= VEX_HWCAPS_PPC64_GX; |
sewardj | f34eb49 | 2011-04-15 11:57:05 +0000 | [diff] [blame] | 1107 | if (have_VX) vai.hwcaps |= VEX_HWCAPS_PPC64_VX; |
sewardj | 5ba075a | 2012-04-02 21:25:14 +0000 | [diff] [blame] | 1108 | if (have_DFP) vai.hwcaps |= VEX_HWCAPS_PPC64_DFP; |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 1109 | |
florian | 7862701 | 2012-10-07 19:47:04 +0000 | [diff] [blame^] | 1110 | VG_(machine_get_cache_info)(&vai); |
| 1111 | |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 1112 | /* But we're not done yet: VG_(machine_ppc64_set_clszB) must be |
| 1113 | called before we're ready to go. */ |
| 1114 | return True; |
| 1115 | } |
| 1116 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1117 | #elif defined(VGA_s390x) |
| 1118 | { |
| 1119 | /* Instruction set detection code borrowed from ppc above. */ |
| 1120 | vki_sigset_t saved_set, tmp_set; |
| 1121 | vki_sigaction_fromK_t saved_sigill_act; |
| 1122 | vki_sigaction_toK_t tmp_sigill_act; |
| 1123 | |
sewardj | 1c6f6ab | 2011-04-27 12:00:51 +0000 | [diff] [blame] | 1124 | volatile Bool have_LDISP, have_EIMM, have_GIE, have_DFP, have_FGX; |
florian | 370bc77 | 2012-08-30 20:30:32 +0000 | [diff] [blame] | 1125 | volatile Bool have_STFLE, have_ETF2, have_ETF3, have_STCKF, have_FPEXT; |
sewardj | 2c3f2ea | 2011-04-13 15:40:10 +0000 | [diff] [blame] | 1126 | Int r, model; |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1127 | |
| 1128 | /* Unblock SIGILL and stash away the old action for that signal */ |
| 1129 | VG_(sigemptyset)(&tmp_set); |
| 1130 | VG_(sigaddset)(&tmp_set, VKI_SIGILL); |
| 1131 | |
| 1132 | r = VG_(sigprocmask)(VKI_SIG_UNBLOCK, &tmp_set, &saved_set); |
| 1133 | vg_assert(r == 0); |
| 1134 | |
| 1135 | r = VG_(sigaction)(VKI_SIGILL, NULL, &saved_sigill_act); |
| 1136 | vg_assert(r == 0); |
| 1137 | tmp_sigill_act = saved_sigill_act; |
| 1138 | |
| 1139 | /* NODEFER: signal handler does not return (from the kernel's point of |
| 1140 | view), hence if it is to successfully catch a signal more than once, |
| 1141 | we need the NODEFER flag. */ |
| 1142 | tmp_sigill_act.sa_flags &= ~VKI_SA_RESETHAND; |
| 1143 | tmp_sigill_act.sa_flags &= ~VKI_SA_SIGINFO; |
| 1144 | tmp_sigill_act.sa_flags |= VKI_SA_NODEFER; |
| 1145 | tmp_sigill_act.ksa_handler = handler_unsup_insn; |
| 1146 | VG_(sigaction)(VKI_SIGILL, &tmp_sigill_act, NULL); |
| 1147 | |
| 1148 | /* Determine hwcaps. Note, we cannot use the stfle insn because it |
| 1149 | is not supported on z900. */ |
| 1150 | |
| 1151 | have_LDISP = True; |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 1152 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1153 | have_LDISP = False; |
| 1154 | } else { |
| 1155 | /* BASR loads the address of the next insn into r1. Needed to avoid |
| 1156 | a segfault in XY. */ |
| 1157 | __asm__ __volatile__("basr %%r1,%%r0\n\t" |
| 1158 | ".long 0xe3001000\n\t" /* XY 0,0(%r1) */ |
| 1159 | ".short 0x0057" : : : "r0", "r1", "cc", "memory"); |
| 1160 | } |
| 1161 | |
| 1162 | have_EIMM = True; |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 1163 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1164 | have_EIMM = False; |
| 1165 | } else { |
| 1166 | __asm__ __volatile__(".long 0xc0090000\n\t" /* iilf r0,0 */ |
| 1167 | ".short 0x0000" : : : "r0", "memory"); |
| 1168 | } |
| 1169 | |
| 1170 | have_GIE = True; |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 1171 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1172 | have_GIE = False; |
| 1173 | } else { |
| 1174 | __asm__ __volatile__(".long 0xc2010000\n\t" /* msfi r0,0 */ |
| 1175 | ".short 0x0000" : : : "r0", "memory"); |
| 1176 | } |
| 1177 | |
| 1178 | have_DFP = True; |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 1179 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1180 | have_DFP = False; |
| 1181 | } else { |
| 1182 | __asm__ __volatile__(".long 0xb3d20000" |
| 1183 | : : : "r0", "cc", "memory"); /* adtr r0,r0,r0 */ |
| 1184 | } |
| 1185 | |
sewardj | 1c6f6ab | 2011-04-27 12:00:51 +0000 | [diff] [blame] | 1186 | have_FGX = True; |
| 1187 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
| 1188 | have_FGX = False; |
| 1189 | } else { |
| 1190 | __asm__ __volatile__(".long 0xb3cd0000" : : : "r0"); /* lgdr r0,f0 */ |
| 1191 | } |
| 1192 | |
florian | 833ffd0 | 2012-08-26 04:23:08 +0000 | [diff] [blame] | 1193 | /* Detect presence of certain facilities using the STFLE insn. |
| 1194 | Note, that these facilities were introduced at the same time or later |
| 1195 | as STFLE, so the absence of STLFE implies the absence of the facility |
| 1196 | we're trying to detect. */ |
florian | d19733c | 2012-01-15 21:02:44 +0000 | [diff] [blame] | 1197 | have_STFLE = True; |
| 1198 | have_ETF2 = False; |
florian | e3d028c | 2012-05-03 01:31:24 +0000 | [diff] [blame] | 1199 | have_ETF3 = False; |
florian | 833ffd0 | 2012-08-26 04:23:08 +0000 | [diff] [blame] | 1200 | have_STCKF = False; |
florian | e968591 | 2012-09-01 23:48:09 +0000 | [diff] [blame] | 1201 | have_FPEXT = False; |
florian | d19733c | 2012-01-15 21:02:44 +0000 | [diff] [blame] | 1202 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
| 1203 | have_STFLE = False; |
| 1204 | } else { |
| 1205 | ULong hoststfle[1]; |
| 1206 | register ULong reg0 asm("0") = 0; /* one double word available */ |
| 1207 | |
| 1208 | __asm__ __volatile__(" .insn s,0xb2b00000,%0\n" /* stfle */ |
| 1209 | : "=m" (hoststfle), "+d"(reg0) |
| 1210 | : : "cc", "memory"); |
| 1211 | if (hoststfle[0] & (1ULL << (63 - 24))) |
| 1212 | have_ETF2 = True; |
florian | e3d028c | 2012-05-03 01:31:24 +0000 | [diff] [blame] | 1213 | if (hoststfle[0] & (1ULL << (63 - 30))) |
| 1214 | have_ETF3 = True; |
florian | 833ffd0 | 2012-08-26 04:23:08 +0000 | [diff] [blame] | 1215 | if (hoststfle[0] & (1ULL << (63 - 25))) |
| 1216 | have_STCKF = True; |
florian | 370bc77 | 2012-08-30 20:30:32 +0000 | [diff] [blame] | 1217 | if (hoststfle[0] & (1ULL << (63 - 37))) |
| 1218 | have_FPEXT = True; |
florian | d19733c | 2012-01-15 21:02:44 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1221 | /* Restore signals */ |
| 1222 | r = VG_(sigaction)(VKI_SIGILL, &saved_sigill_act, NULL); |
| 1223 | vg_assert(r == 0); |
| 1224 | r = VG_(sigprocmask)(VKI_SIG_SETMASK, &saved_set, NULL); |
| 1225 | vg_assert(r == 0); |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1226 | va = VexArchS390X; |
| 1227 | |
sewardj | 2c3f2ea | 2011-04-13 15:40:10 +0000 | [diff] [blame] | 1228 | model = VG_(get_machine_model)(); |
| 1229 | |
florian | 4e63b8e | 2012-04-22 03:50:20 +0000 | [diff] [blame] | 1230 | /* If the model is "unknown" don't treat this as an error. Assume |
| 1231 | this is a brand-new machine model for which we don't have the |
| 1232 | identification yet. Keeping fingers crossed. */ |
| 1233 | |
sewardj | 1c6f6ab | 2011-04-27 12:00:51 +0000 | [diff] [blame] | 1234 | VG_(debugLog)(1, "machine", "machine %d LDISP %d EIMM %d GIE %d DFP %d " |
florian | 833ffd0 | 2012-08-26 04:23:08 +0000 | [diff] [blame] | 1235 | "FGX %d STFLE %d ETF2 %d ETF3 %d STCKF %d\n", |
| 1236 | model, have_LDISP, have_EIMM, have_GIE, have_DFP, have_FGX, |
| 1237 | have_STFLE, have_ETF2, have_ETF3, have_STCKF); |
sewardj | 2c3f2ea | 2011-04-13 15:40:10 +0000 | [diff] [blame] | 1238 | |
sewardj | 2c3f2ea | 2011-04-13 15:40:10 +0000 | [diff] [blame] | 1239 | vai.hwcaps = model; |
| 1240 | if (have_LDISP) { |
| 1241 | /* Use long displacement only on machines >= z990. For all other machines |
| 1242 | it is millicoded and therefore slow. */ |
| 1243 | if (model >= VEX_S390X_MODEL_Z990) |
| 1244 | vai.hwcaps |= VEX_HWCAPS_S390X_LDISP; |
| 1245 | } |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1246 | if (have_EIMM) vai.hwcaps |= VEX_HWCAPS_S390X_EIMM; |
| 1247 | if (have_GIE) vai.hwcaps |= VEX_HWCAPS_S390X_GIE; |
| 1248 | if (have_DFP) vai.hwcaps |= VEX_HWCAPS_S390X_DFP; |
sewardj | 1c6f6ab | 2011-04-27 12:00:51 +0000 | [diff] [blame] | 1249 | if (have_FGX) vai.hwcaps |= VEX_HWCAPS_S390X_FGX; |
florian | d19733c | 2012-01-15 21:02:44 +0000 | [diff] [blame] | 1250 | if (have_ETF2) vai.hwcaps |= VEX_HWCAPS_S390X_ETF2; |
florian | e3d028c | 2012-05-03 01:31:24 +0000 | [diff] [blame] | 1251 | if (have_ETF3) vai.hwcaps |= VEX_HWCAPS_S390X_ETF3; |
florian | 68aba52 | 2012-04-21 15:43:25 +0000 | [diff] [blame] | 1252 | if (have_STFLE) vai.hwcaps |= VEX_HWCAPS_S390X_STFLE; |
florian | 833ffd0 | 2012-08-26 04:23:08 +0000 | [diff] [blame] | 1253 | if (have_STCKF) vai.hwcaps |= VEX_HWCAPS_S390X_STCKF; |
florian | 370bc77 | 2012-08-30 20:30:32 +0000 | [diff] [blame] | 1254 | if (have_FPEXT) vai.hwcaps |= VEX_HWCAPS_S390X_FPEXT; |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1255 | |
sewardj | 2c3f2ea | 2011-04-13 15:40:10 +0000 | [diff] [blame] | 1256 | VG_(debugLog)(1, "machine", "hwcaps = 0x%x\n", vai.hwcaps); |
| 1257 | |
florian | 7862701 | 2012-10-07 19:47:04 +0000 | [diff] [blame^] | 1258 | VG_(machine_get_cache_info)(&vai); |
| 1259 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1260 | return True; |
| 1261 | } |
| 1262 | |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 1263 | #elif defined(VGA_arm) |
| 1264 | { |
sewardj | 1dbd337 | 2010-08-22 12:21:14 +0000 | [diff] [blame] | 1265 | /* Same instruction set detection algorithm as for ppc32. */ |
| 1266 | vki_sigset_t saved_set, tmp_set; |
| 1267 | vki_sigaction_fromK_t saved_sigill_act, saved_sigfpe_act; |
| 1268 | vki_sigaction_toK_t tmp_sigill_act, tmp_sigfpe_act; |
| 1269 | |
| 1270 | volatile Bool have_VFP, have_VFP2, have_VFP3, have_NEON; |
| 1271 | volatile Int archlevel; |
| 1272 | Int r; |
| 1273 | |
| 1274 | /* This is a kludge. Really we ought to back-convert saved_act |
| 1275 | into a toK_t using VG_(convert_sigaction_fromK_to_toK), but |
| 1276 | since that's a no-op on all ppc64 platforms so far supported, |
| 1277 | it's not worth the typing effort. At least include most basic |
| 1278 | sanity check: */ |
| 1279 | vg_assert(sizeof(vki_sigaction_fromK_t) == sizeof(vki_sigaction_toK_t)); |
| 1280 | |
| 1281 | VG_(sigemptyset)(&tmp_set); |
| 1282 | VG_(sigaddset)(&tmp_set, VKI_SIGILL); |
| 1283 | VG_(sigaddset)(&tmp_set, VKI_SIGFPE); |
| 1284 | |
| 1285 | r = VG_(sigprocmask)(VKI_SIG_UNBLOCK, &tmp_set, &saved_set); |
| 1286 | vg_assert(r == 0); |
| 1287 | |
| 1288 | r = VG_(sigaction)(VKI_SIGILL, NULL, &saved_sigill_act); |
| 1289 | vg_assert(r == 0); |
| 1290 | tmp_sigill_act = saved_sigill_act; |
| 1291 | |
| 1292 | VG_(sigaction)(VKI_SIGFPE, NULL, &saved_sigfpe_act); |
| 1293 | tmp_sigfpe_act = saved_sigfpe_act; |
| 1294 | |
| 1295 | /* NODEFER: signal handler does not return (from the kernel's point of |
| 1296 | view), hence if it is to successfully catch a signal more than once, |
| 1297 | we need the NODEFER flag. */ |
| 1298 | tmp_sigill_act.sa_flags &= ~VKI_SA_RESETHAND; |
| 1299 | tmp_sigill_act.sa_flags &= ~VKI_SA_SIGINFO; |
| 1300 | tmp_sigill_act.sa_flags |= VKI_SA_NODEFER; |
| 1301 | tmp_sigill_act.ksa_handler = handler_unsup_insn; |
| 1302 | VG_(sigaction)(VKI_SIGILL, &tmp_sigill_act, NULL); |
| 1303 | |
| 1304 | tmp_sigfpe_act.sa_flags &= ~VKI_SA_RESETHAND; |
| 1305 | tmp_sigfpe_act.sa_flags &= ~VKI_SA_SIGINFO; |
| 1306 | tmp_sigfpe_act.sa_flags |= VKI_SA_NODEFER; |
| 1307 | tmp_sigfpe_act.ksa_handler = handler_unsup_insn; |
| 1308 | VG_(sigaction)(VKI_SIGFPE, &tmp_sigfpe_act, NULL); |
| 1309 | |
| 1310 | /* VFP insns */ |
| 1311 | have_VFP = True; |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 1312 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
sewardj | 1dbd337 | 2010-08-22 12:21:14 +0000 | [diff] [blame] | 1313 | have_VFP = False; |
| 1314 | } else { |
| 1315 | __asm__ __volatile__(".word 0xEEB02B42"); /* VMOV.F64 d2, d2 */ |
| 1316 | } |
| 1317 | /* There are several generation of VFP extension but they differs very |
| 1318 | little so for now we will not distinguish them. */ |
| 1319 | have_VFP2 = have_VFP; |
| 1320 | have_VFP3 = have_VFP; |
| 1321 | |
| 1322 | /* NEON insns */ |
| 1323 | have_NEON = True; |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 1324 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
sewardj | 1dbd337 | 2010-08-22 12:21:14 +0000 | [diff] [blame] | 1325 | have_NEON = False; |
| 1326 | } else { |
| 1327 | __asm__ __volatile__(".word 0xF2244154"); /* VMOV q2, q2 */ |
| 1328 | } |
| 1329 | |
| 1330 | /* ARM architecture level */ |
| 1331 | archlevel = 5; /* v5 will be base level */ |
| 1332 | if (archlevel < 7) { |
| 1333 | archlevel = 7; |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 1334 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
sewardj | 1dbd337 | 2010-08-22 12:21:14 +0000 | [diff] [blame] | 1335 | archlevel = 5; |
| 1336 | } else { |
| 1337 | __asm__ __volatile__(".word 0xF45FF000"); /* PLI [PC,#-0] */ |
| 1338 | } |
| 1339 | } |
| 1340 | if (archlevel < 6) { |
| 1341 | archlevel = 6; |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 1342 | if (VG_MINIMAL_SETJMP(env_unsup_insn)) { |
sewardj | 1dbd337 | 2010-08-22 12:21:14 +0000 | [diff] [blame] | 1343 | archlevel = 5; |
| 1344 | } else { |
| 1345 | __asm__ __volatile__(".word 0xE6822012"); /* PKHBT r2, r2, r2 */ |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | VG_(convert_sigaction_fromK_to_toK)(&saved_sigill_act, &tmp_sigill_act); |
| 1350 | VG_(convert_sigaction_fromK_to_toK)(&saved_sigfpe_act, &tmp_sigfpe_act); |
| 1351 | VG_(sigaction)(VKI_SIGILL, &tmp_sigill_act, NULL); |
| 1352 | VG_(sigaction)(VKI_SIGFPE, &tmp_sigfpe_act, NULL); |
| 1353 | VG_(sigprocmask)(VKI_SIG_SETMASK, &saved_set, NULL); |
| 1354 | |
| 1355 | VG_(debugLog)(1, "machine", "ARMv%d VFP %d VFP2 %d VFP3 %d NEON %d\n", |
| 1356 | archlevel, (Int)have_VFP, (Int)have_VFP2, (Int)have_VFP3, |
| 1357 | (Int)have_NEON); |
| 1358 | |
| 1359 | VG_(machine_arm_archlevel) = archlevel; |
| 1360 | |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 1361 | va = VexArchARM; |
sewardj | 1dbd337 | 2010-08-22 12:21:14 +0000 | [diff] [blame] | 1362 | |
| 1363 | vai.hwcaps = VEX_ARM_ARCHLEVEL(archlevel); |
| 1364 | if (have_VFP3) vai.hwcaps |= VEX_HWCAPS_ARM_VFP3; |
| 1365 | if (have_VFP2) vai.hwcaps |= VEX_HWCAPS_ARM_VFP2; |
| 1366 | if (have_VFP) vai.hwcaps |= VEX_HWCAPS_ARM_VFP; |
| 1367 | if (have_NEON) vai.hwcaps |= VEX_HWCAPS_ARM_NEON; |
| 1368 | |
florian | 7862701 | 2012-10-07 19:47:04 +0000 | [diff] [blame^] | 1369 | VG_(machine_get_cache_info)(&vai); |
| 1370 | |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 1371 | return True; |
| 1372 | } |
| 1373 | |
sewardj | 5db1540 | 2012-06-07 09:13:21 +0000 | [diff] [blame] | 1374 | #elif defined(VGA_mips32) |
| 1375 | { |
| 1376 | va = VexArchMIPS32; |
| 1377 | UInt model = VG_(get_machine_model)(); |
| 1378 | if (model== -1) |
| 1379 | return False; |
| 1380 | |
| 1381 | vai.hwcaps = model; |
florian | 7862701 | 2012-10-07 19:47:04 +0000 | [diff] [blame^] | 1382 | |
| 1383 | VG_(machine_get_cache_info)(&vai); |
| 1384 | |
sewardj | 5db1540 | 2012-06-07 09:13:21 +0000 | [diff] [blame] | 1385 | return True; |
| 1386 | } |
| 1387 | |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 1388 | #else |
| 1389 | # error "Unknown arch" |
| 1390 | #endif |
| 1391 | } |
| 1392 | |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 1393 | /* Notify host cpu cache line size. */ |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 1394 | #if defined(VGA_ppc32) |
| 1395 | void VG_(machine_ppc32_set_clszB)( Int szB ) |
| 1396 | { |
| 1397 | vg_assert(hwcaps_done); |
| 1398 | |
| 1399 | /* Either the value must not have been set yet (zero) or we can |
| 1400 | tolerate it being set to the same value multiple times, as the |
| 1401 | stack scanning logic in m_main is a bit stupid. */ |
cerion | 1f0d814 | 2005-12-23 00:57:03 +0000 | [diff] [blame] | 1402 | vg_assert(vai.ppc_cache_line_szB == 0 |
| 1403 | || vai.ppc_cache_line_szB == szB); |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 1404 | |
sewardj | 89230ca | 2008-05-29 16:39:57 +0000 | [diff] [blame] | 1405 | vg_assert(szB == 32 || szB == 64 || szB == 128); |
cerion | 1f0d814 | 2005-12-23 00:57:03 +0000 | [diff] [blame] | 1406 | vai.ppc_cache_line_szB = szB; |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 1407 | } |
| 1408 | #endif |
| 1409 | |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 1410 | |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 1411 | /* Notify host cpu cache line size. */ |
| 1412 | #if defined(VGA_ppc64) |
| 1413 | void VG_(machine_ppc64_set_clszB)( Int szB ) |
| 1414 | { |
| 1415 | vg_assert(hwcaps_done); |
| 1416 | |
| 1417 | /* Either the value must not have been set yet (zero) or we can |
| 1418 | tolerate it being set to the same value multiple times, as the |
| 1419 | stack scanning logic in m_main is a bit stupid. */ |
cerion | 1f0d814 | 2005-12-23 00:57:03 +0000 | [diff] [blame] | 1420 | vg_assert(vai.ppc_cache_line_szB == 0 |
| 1421 | || vai.ppc_cache_line_szB == szB); |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 1422 | |
sewardj | 89230ca | 2008-05-29 16:39:57 +0000 | [diff] [blame] | 1423 | vg_assert(szB == 32 || szB == 64 || szB == 128); |
cerion | 1f0d814 | 2005-12-23 00:57:03 +0000 | [diff] [blame] | 1424 | vai.ppc_cache_line_szB = szB; |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 1425 | } |
| 1426 | #endif |
| 1427 | |
| 1428 | |
sewardj | a3551be | 2010-09-09 07:25:58 +0000 | [diff] [blame] | 1429 | /* Notify host's ability to handle NEON instructions. */ |
| 1430 | #if defined(VGA_arm) |
| 1431 | void VG_(machine_arm_set_has_NEON)( Bool has_neon ) |
| 1432 | { |
| 1433 | vg_assert(hwcaps_done); |
| 1434 | /* There's nothing else we can sanity check. */ |
| 1435 | |
| 1436 | if (has_neon) { |
| 1437 | vai.hwcaps |= VEX_HWCAPS_ARM_NEON; |
| 1438 | } else { |
| 1439 | vai.hwcaps &= ~VEX_HWCAPS_ARM_NEON; |
| 1440 | } |
| 1441 | } |
| 1442 | #endif |
| 1443 | |
| 1444 | |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 1445 | /* Fetch host cpu info, once established. */ |
| 1446 | void VG_(machine_get_VexArchInfo)( /*OUT*/VexArch* pVa, |
| 1447 | /*OUT*/VexArchInfo* pVai ) |
| 1448 | { |
| 1449 | vg_assert(hwcaps_done); |
sewardj | e3826cf | 2005-11-13 00:30:22 +0000 | [diff] [blame] | 1450 | if (pVa) *pVa = va; |
| 1451 | if (pVai) *pVai = vai; |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 1452 | } |
sewardj | 7821e2e | 2005-08-08 00:35:46 +0000 | [diff] [blame] | 1453 | |
| 1454 | |
sewardj | 98763d5 | 2012-06-03 22:40:07 +0000 | [diff] [blame] | 1455 | /* Returns the size of the largest guest register that we will |
| 1456 | simulate in this run. This depends on both the guest architecture |
| 1457 | and on the specific capabilities we are simulating for that guest |
| 1458 | (eg, AVX or non-AVX ?, for amd64). Should return either 4, 8, 16 |
| 1459 | or 32. General rule: if in doubt, return a value larger than |
| 1460 | reality. |
| 1461 | |
| 1462 | This information is needed by Cachegrind and Callgrind to decide |
| 1463 | what the minimum cache line size they are prepared to simulate is. |
| 1464 | Basically require that the minimum cache line size is at least as |
| 1465 | large as the largest register that might get transferred to/from |
| 1466 | memory, so as to guarantee that any such transaction can straddle |
| 1467 | at most 2 cache lines. |
| 1468 | */ |
| 1469 | Int VG_(machine_get_size_of_largest_guest_register) ( void ) |
| 1470 | { |
| 1471 | vg_assert(hwcaps_done); |
| 1472 | /* Once hwcaps_done is True, we can fish around inside va/vai to |
| 1473 | find the information we need. */ |
| 1474 | |
| 1475 | # if defined(VGA_x86) |
| 1476 | vg_assert(va == VexArchX86); |
| 1477 | /* We don't support AVX, so 32 is out. At the other end, even if |
| 1478 | we don't support any SSE, the X87 can generate 10 byte |
| 1479 | transfers, so let's say 16 to be on the safe side. Hence the |
| 1480 | answer is always 16. */ |
| 1481 | return 16; |
| 1482 | |
| 1483 | # elif defined(VGA_amd64) |
| 1484 | /* if AVX then 32 else 16 */ |
| 1485 | return (vai.hwcaps & VEX_HWCAPS_AMD64_AVX) ? 32 : 16; |
| 1486 | |
| 1487 | # elif defined(VGA_ppc32) |
| 1488 | /* 8 if boring; 16 if signs of Altivec or other exotic stuff */ |
| 1489 | if (vai.hwcaps & VEX_HWCAPS_PPC32_V) return 16; |
| 1490 | if (vai.hwcaps & VEX_HWCAPS_PPC32_VX) return 16; |
| 1491 | if (vai.hwcaps & VEX_HWCAPS_PPC32_DFP) return 16; |
| 1492 | return 8; |
| 1493 | |
| 1494 | # elif defined(VGA_ppc64) |
| 1495 | /* 8 if boring; 16 if signs of Altivec or other exotic stuff */ |
| 1496 | if (vai.hwcaps & VEX_HWCAPS_PPC64_V) return 16; |
| 1497 | if (vai.hwcaps & VEX_HWCAPS_PPC64_VX) return 16; |
| 1498 | if (vai.hwcaps & VEX_HWCAPS_PPC64_DFP) return 16; |
| 1499 | return 8; |
| 1500 | |
| 1501 | # elif defined(VGA_s390x) |
| 1502 | return 8; |
| 1503 | |
| 1504 | # elif defined(VGA_arm) |
| 1505 | /* Really it depends whether or not we have NEON, but let's just |
| 1506 | assume we always do. */ |
| 1507 | return 16; |
| 1508 | |
sewardj | 5db1540 | 2012-06-07 09:13:21 +0000 | [diff] [blame] | 1509 | # elif defined(VGA_mips32) |
| 1510 | /* The guest state implies 4, but that can't really be true, can |
| 1511 | it? */ |
| 1512 | return 8; |
| 1513 | |
sewardj | 98763d5 | 2012-06-03 22:40:07 +0000 | [diff] [blame] | 1514 | # else |
| 1515 | # error "Unknown arch" |
| 1516 | # endif |
| 1517 | } |
| 1518 | |
| 1519 | |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 1520 | // Given a pointer to a function as obtained by "& functionname" in C, |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 1521 | // produce a pointer to the actual entry point for the function. |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 1522 | void* VG_(fnptr_to_fnentry)( void* f ) |
| 1523 | { |
sewardj | 6e9de46 | 2011-06-28 07:25:29 +0000 | [diff] [blame] | 1524 | # if defined(VGP_x86_linux) || defined(VGP_amd64_linux) \ |
| 1525 | || defined(VGP_arm_linux) \ |
| 1526 | || defined(VGP_ppc32_linux) || defined(VGO_darwin) \ |
sewardj | 5db1540 | 2012-06-07 09:13:21 +0000 | [diff] [blame] | 1527 | || defined(VGP_s390x_linux) || defined(VGP_mips32_linux) |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 1528 | return f; |
sewardj | 6e9de46 | 2011-06-28 07:25:29 +0000 | [diff] [blame] | 1529 | # elif defined(VGP_ppc64_linux) |
| 1530 | /* ppc64-linux uses the AIX scheme, in which f is a pointer to a |
| 1531 | 3-word function descriptor, of which the first word is the entry |
| 1532 | address. */ |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 1533 | UWord* descr = (UWord*)f; |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 1534 | return (void*)(descr[0]); |
sewardj | 6e9de46 | 2011-06-28 07:25:29 +0000 | [diff] [blame] | 1535 | # else |
| 1536 | # error "Unknown platform" |
| 1537 | # endif |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 1538 | } |
| 1539 | |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 1540 | /*--------------------------------------------------------------------*/ |
| 1541 | /*--- end ---*/ |
| 1542 | /*--------------------------------------------------------------------*/ |