njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- Machine-related things. pub_core_machine.h ---*/ |
| 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
| 9 | |
sewardj | 03f8d3f | 2012-08-05 15:46:46 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2012 Julian Seward |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 11 | jseward@acm.org |
| 12 | |
| 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
| 28 | The GNU General Public License is contained in the file COPYING. |
| 29 | */ |
| 30 | |
| 31 | #ifndef __PUB_CORE_MACHINE_H |
| 32 | #define __PUB_CORE_MACHINE_H |
| 33 | |
| 34 | //-------------------------------------------------------------------- |
| 35 | // PURPOSE: This module contains code related to the particular |
| 36 | // architecture, things like accessing guest state, endianness, word size, |
| 37 | // etc. |
| 38 | //-------------------------------------------------------------------- |
| 39 | |
| 40 | #include "pub_tool_machine.h" |
| 41 | |
njn | 265aae7 | 2009-05-19 01:49:50 +0000 | [diff] [blame] | 42 | // XXX: this is *really* the wrong spot for these things |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 43 | #if defined(VGP_x86_linux) |
sewardj | 6e340c7 | 2005-07-10 00:53:42 +0000 | [diff] [blame] | 44 | # define VG_ELF_DATA2XXX ELFDATA2LSB |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 45 | # define VG_ELF_MACHINE EM_386 |
| 46 | # define VG_ELF_CLASS ELFCLASS32 |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 47 | # undef VG_PLAT_USES_PPCTOC |
| 48 | #elif defined(VGP_amd64_linux) |
sewardj | 6e340c7 | 2005-07-10 00:53:42 +0000 | [diff] [blame] | 49 | # define VG_ELF_DATA2XXX ELFDATA2LSB |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 50 | # define VG_ELF_MACHINE EM_X86_64 |
| 51 | # define VG_ELF_CLASS ELFCLASS64 |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 52 | # undef VG_PLAT_USES_PPCTOC |
| 53 | #elif defined(VGP_ppc32_linux) |
sewardj | 6e340c7 | 2005-07-10 00:53:42 +0000 | [diff] [blame] | 54 | # define VG_ELF_DATA2XXX ELFDATA2MSB |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 55 | # define VG_ELF_MACHINE EM_PPC |
| 56 | # define VG_ELF_CLASS ELFCLASS32 |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 57 | # undef VG_PLAT_USES_PPCTOC |
| 58 | #elif defined(VGP_ppc64_linux) |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 59 | # define VG_ELF_DATA2XXX ELFDATA2MSB |
| 60 | # define VG_ELF_MACHINE EM_PPC64 |
| 61 | # define VG_ELF_CLASS ELFCLASS64 |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 62 | # define VG_PLAT_USES_PPCTOC 1 |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 63 | #elif defined(VGP_arm_linux) |
| 64 | # define VG_ELF_DATA2XXX ELFDATA2LSB |
| 65 | # define VG_ELF_MACHINE EM_ARM |
| 66 | # define VG_ELF_CLASS ELFCLASS32 |
| 67 | # undef VG_PLAT_USES_PPCTOC |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 68 | #elif defined(VGO_darwin) |
| 69 | # undef VG_ELF_DATA2XXX |
| 70 | # undef VG_ELF_MACHINE |
| 71 | # undef VG_ELF_CLASS |
| 72 | # undef VG_PLAT_USES_PPCTOC |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 73 | #elif defined(VGP_s390x_linux) |
| 74 | # define VG_ELF_DATA2XXX ELFDATA2MSB |
| 75 | # define VG_ELF_MACHINE EM_S390 |
| 76 | # define VG_ELF_CLASS ELFCLASS64 |
| 77 | # undef VG_PLAT_USES_PPCTOC |
sewardj | 5db1540 | 2012-06-07 09:13:21 +0000 | [diff] [blame] | 78 | #elif defined(VGP_mips32_linux) |
| 79 | # if defined (VG_LITTLEENDIAN) |
| 80 | # define VG_ELF_DATA2XXX ELFDATA2LSB |
| 81 | # elif defined (VG_BIGENDIAN) |
| 82 | # define VG_ELF_DATA2XXX ELFDATA2MSB |
| 83 | # else |
| 84 | # error "Unknown endianness" |
| 85 | # endif |
| 86 | # define VG_ELF_MACHINE EM_MIPS |
| 87 | # define VG_ELF_CLASS ELFCLASS32 |
| 88 | # undef VG_PLAT_USES_PPCTOC |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 89 | #else |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 90 | # error Unknown platform |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 91 | #endif |
| 92 | |
| 93 | #if defined(VGA_x86) |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 94 | # define VG_INSTR_PTR guest_EIP |
| 95 | # define VG_STACK_PTR guest_ESP |
| 96 | # define VG_FRAME_PTR guest_EBP |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 97 | #elif defined(VGA_amd64) |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 98 | # define VG_INSTR_PTR guest_RIP |
| 99 | # define VG_STACK_PTR guest_RSP |
| 100 | # define VG_FRAME_PTR guest_RBP |
cerion | 85665ca | 2005-06-20 15:51:07 +0000 | [diff] [blame] | 101 | #elif defined(VGA_ppc32) |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 102 | # define VG_INSTR_PTR guest_CIA |
| 103 | # define VG_STACK_PTR guest_GPR1 |
| 104 | # define VG_FRAME_PTR guest_GPR1 // No frame ptr for PPC |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 105 | #elif defined(VGA_ppc64) |
| 106 | # define VG_INSTR_PTR guest_CIA |
| 107 | # define VG_STACK_PTR guest_GPR1 |
| 108 | # define VG_FRAME_PTR guest_GPR1 // No frame ptr for PPC |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 109 | #elif defined(VGA_arm) |
sewardj | 1dbd337 | 2010-08-22 12:21:14 +0000 | [diff] [blame] | 110 | # define VG_INSTR_PTR guest_R15T |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 111 | # define VG_STACK_PTR guest_R13 |
| 112 | # define VG_FRAME_PTR guest_R11 |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 113 | #elif defined(VGA_s390x) |
| 114 | # define VG_INSTR_PTR guest_IA |
| 115 | # define VG_STACK_PTR guest_SP |
| 116 | # define VG_FRAME_PTR guest_FP |
florian | ccb843b | 2012-02-26 17:51:28 +0000 | [diff] [blame] | 117 | # define VG_FPC_REG guest_fpc |
sewardj | 5db1540 | 2012-06-07 09:13:21 +0000 | [diff] [blame] | 118 | #elif defined(VGA_mips32) |
| 119 | # define VG_INSTR_PTR guest_PC |
| 120 | # define VG_STACK_PTR guest_r29 |
| 121 | # define VG_FRAME_PTR guest_r30 |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 122 | #else |
| 123 | # error Unknown arch |
| 124 | #endif |
| 125 | |
sewardj | 7821e2e | 2005-08-08 00:35:46 +0000 | [diff] [blame] | 126 | |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 127 | // Offsets for the Vex state |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 128 | #define VG_O_STACK_PTR (offsetof(VexGuestArchState, VG_STACK_PTR)) |
njn | cda2f0f | 2009-05-18 02:12:08 +0000 | [diff] [blame] | 129 | #define VG_O_INSTR_PTR (offsetof(VexGuestArchState, VG_INSTR_PTR)) |
florian | ccb843b | 2012-02-26 17:51:28 +0000 | [diff] [blame] | 130 | #define VG_O_FPC_REG (offsetof(VexGuestArchState, VG_FPC_REG)) |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 131 | |
sewardj | 7821e2e | 2005-08-08 00:35:46 +0000 | [diff] [blame] | 132 | |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 133 | //------------------------------------------------------------- |
sewardj | 1dbd337 | 2010-08-22 12:21:14 +0000 | [diff] [blame] | 134 | // Guest state accessors that are not visible to tools. The only |
| 135 | // ones that are visible are get_IP and get_SP. |
| 136 | |
| 137 | //Addr VG_(get_IP) ( ThreadId tid ); // in pub_tool_machine.h |
| 138 | //Addr VG_(get_SP) ( ThreadId tid ); // in pub_tool_machine.h |
| 139 | Addr VG_(get_FP) ( ThreadId tid ); |
| 140 | |
| 141 | void VG_(set_IP) ( ThreadId tid, Addr encip ); |
| 142 | void VG_(set_SP) ( ThreadId tid, Addr sp ); |
| 143 | |
| 144 | |
| 145 | //------------------------------------------------------------- |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 146 | // Get hold of the values needed for a stack unwind, for the specified |
| 147 | // (client) thread. |
| 148 | void VG_(get_UnwindStartRegs) ( /*OUT*/UnwindStartRegs* regs, |
| 149 | ThreadId tid ); |
| 150 | |
| 151 | |
| 152 | //------------------------------------------------------------- |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 153 | /* Details about the capabilities of the underlying (host) CPU. These |
| 154 | details are acquired by (1) enquiring with the CPU at startup, or |
cerion | 1f0d814 | 2005-12-23 00:57:03 +0000 | [diff] [blame] | 155 | (2) from the AT_SYSINFO entries the kernel gave us (ppc cache |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 156 | line size). It's a bit nasty in the sense that there's no obvious |
| 157 | way to stop uses of some of this info before it's ready to go. |
sewardj | 10f08cf | 2005-06-29 10:16:14 +0000 | [diff] [blame] | 158 | |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 159 | Current dependencies are: |
| 160 | |
| 161 | x86: initially: call VG_(machine_get_hwcaps) |
| 162 | |
| 163 | then safe to use VG_(machine_get_VexArchInfo) |
| 164 | and VG_(machine_x86_have_mxcsr) |
| 165 | ------------- |
| 166 | amd64: initially: call VG_(machine_get_hwcaps) |
| 167 | |
| 168 | then safe to use VG_(machine_get_VexArchInfo) |
| 169 | ------------- |
| 170 | ppc32: initially: call VG_(machine_get_hwcaps) |
| 171 | call VG_(machine_ppc32_set_clszB) |
| 172 | |
| 173 | then safe to use VG_(machine_get_VexArchInfo) |
sewardj | 2c36d42 | 2005-11-13 01:59:22 +0000 | [diff] [blame] | 174 | and VG_(machine_ppc32_has_FP) |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 175 | and VG_(machine_ppc32_has_VMX) |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 176 | ------------- |
| 177 | ppc64: initially: call VG_(machine_get_hwcaps) |
| 178 | call VG_(machine_ppc64_set_clszB) |
| 179 | |
| 180 | then safe to use VG_(machine_get_VexArchInfo) |
| 181 | and VG_(machine_ppc64_has_VMX) |
sewardj | a3551be | 2010-09-09 07:25:58 +0000 | [diff] [blame] | 182 | ------------- |
| 183 | arm: initially: call VG_(machine_get_hwcaps) |
| 184 | call VG_(machine_arm_set_has_NEON) |
| 185 | |
| 186 | then safe to use VG_(machine_get_VexArchInfo) |
florian | 0daa4e3 | 2012-04-22 02:48:20 +0000 | [diff] [blame] | 187 | ------------- |
| 188 | s390x: initially: call VG_(machine_get_hwcaps) |
| 189 | |
| 190 | then safe to use VG_(machine_get_VexArchInfo) |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 191 | |
| 192 | VG_(machine_get_hwcaps) may use signals (although it attempts to |
| 193 | leave signal state unchanged) and therefore should only be |
| 194 | called before m_main sets up the client's signal state. |
| 195 | */ |
| 196 | |
| 197 | /* Determine what insn set and insn set variant the host has, and |
| 198 | record it. To be called once at system startup. Returns False if |
| 199 | this a CPU incapable of running Valgrind. */ |
| 200 | extern Bool VG_(machine_get_hwcaps)( void ); |
| 201 | |
florian | 7862701 | 2012-10-07 19:47:04 +0000 | [diff] [blame] | 202 | /* Determine information about the cache system this host has and |
| 203 | record it. Returns False, if cache information cannot be auto-detected. */ |
| 204 | extern Bool VG_(machine_get_cache_info)( VexArchInfo * ); |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 205 | |
| 206 | /* Notify host cpu cache line size, as per above comment. */ |
cerion | bc28f66 | 2005-09-13 11:13:43 +0000 | [diff] [blame] | 207 | #if defined(VGA_ppc32) |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 208 | extern void VG_(machine_ppc32_set_clszB)( Int ); |
sewardj | 10f08cf | 2005-06-29 10:16:14 +0000 | [diff] [blame] | 209 | #endif |
| 210 | |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 211 | #if defined(VGA_ppc64) |
| 212 | extern void VG_(machine_ppc64_set_clszB)( Int ); |
| 213 | #endif |
| 214 | |
sewardj | a3551be | 2010-09-09 07:25:58 +0000 | [diff] [blame] | 215 | #if defined(VGA_arm) |
| 216 | extern void VG_(machine_arm_set_has_NEON)( Bool ); |
| 217 | #endif |
| 218 | |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 219 | /* X86: set to 1 if the host is able to do {ld,st}mxcsr (load/store |
| 220 | the SSE control/status register), else zero. Is referenced from |
| 221 | assembly code, so do not change from a 32-bit int. */ |
sewardj | 7821e2e | 2005-08-08 00:35:46 +0000 | [diff] [blame] | 222 | #if defined(VGA_x86) |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 223 | extern UInt VG_(machine_x86_have_mxcsr); |
sewardj | 7821e2e | 2005-08-08 00:35:46 +0000 | [diff] [blame] | 224 | #endif |
| 225 | |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 226 | /* PPC32: set to 1 if FP instructions are supported in user-space, |
| 227 | else 0. Is referenced from assembly code, so do not change from a |
| 228 | 32-bit int. */ |
| 229 | #if defined(VGA_ppc32) |
sewardj | 2c36d42 | 2005-11-13 01:59:22 +0000 | [diff] [blame] | 230 | extern UInt VG_(machine_ppc32_has_FP); |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 231 | #endif |
| 232 | |
| 233 | /* PPC32: set to 1 if Altivec instructions are supported in |
| 234 | user-space, else 0. Is referenced from assembly code, so do not |
| 235 | change from a 32-bit int. */ |
| 236 | #if defined(VGA_ppc32) |
| 237 | extern UInt VG_(machine_ppc32_has_VMX); |
| 238 | #endif |
sewardj | 7821e2e | 2005-08-08 00:35:46 +0000 | [diff] [blame] | 239 | |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 240 | /* PPC64: set to 1 if Altivec instructions are supported in |
| 241 | user-space, else 0. Is referenced from assembly code, so do not |
| 242 | change from a 64-bit int. */ |
| 243 | #if defined(VGA_ppc64) |
| 244 | extern ULong VG_(machine_ppc64_has_VMX); |
| 245 | #endif |
| 246 | |
sewardj | 1dbd337 | 2010-08-22 12:21:14 +0000 | [diff] [blame] | 247 | #if defined(VGA_arm) |
| 248 | extern Int VG_(machine_arm_archlevel); |
| 249 | #endif |
| 250 | |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 251 | #endif // __PUB_CORE_MACHINE_H |
| 252 | |
| 253 | /*--------------------------------------------------------------------*/ |
| 254 | /*--- end ---*/ |
| 255 | /*--------------------------------------------------------------------*/ |