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 | 9ebd6e0 | 2007-01-08 06:01:59 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2007 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 | |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 42 | #if defined(VGP_x86_linux) |
sewardj | 6e340c7 | 2005-07-10 00:53:42 +0000 | [diff] [blame] | 43 | # define VG_ELF_DATA2XXX ELFDATA2LSB |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 44 | # define VG_ELF_MACHINE EM_386 |
| 45 | # define VG_ELF_CLASS ELFCLASS32 |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 46 | # undef VG_PLAT_USES_PPCTOC |
| 47 | #elif defined(VGP_amd64_linux) |
sewardj | 6e340c7 | 2005-07-10 00:53:42 +0000 | [diff] [blame] | 48 | # define VG_ELF_DATA2XXX ELFDATA2LSB |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 49 | # define VG_ELF_MACHINE EM_X86_64 |
| 50 | # define VG_ELF_CLASS ELFCLASS64 |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 51 | # undef VG_PLAT_USES_PPCTOC |
| 52 | #elif defined(VGP_ppc32_linux) |
sewardj | 6e340c7 | 2005-07-10 00:53:42 +0000 | [diff] [blame] | 53 | # define VG_ELF_DATA2XXX ELFDATA2MSB |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 54 | # define VG_ELF_MACHINE EM_PPC |
| 55 | # define VG_ELF_CLASS ELFCLASS32 |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 56 | # undef VG_PLAT_USES_PPCTOC |
| 57 | #elif defined(VGP_ppc64_linux) |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 58 | # define VG_ELF_DATA2XXX ELFDATA2MSB |
| 59 | # define VG_ELF_MACHINE EM_PPC64 |
| 60 | # define VG_ELF_CLASS ELFCLASS64 |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 61 | # define VG_PLAT_USES_PPCTOC 1 |
| 62 | #elif defined(VGO_aix5) |
| 63 | # undef VG_ELF_DATA2XXX |
| 64 | # undef VG_ELF_MACHINE |
| 65 | # undef VG_ELF_CLASS |
| 66 | # define VG_PLAT_USES_PPCTOC 1 |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 67 | #else |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 68 | # error Unknown platform |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 69 | #endif |
| 70 | |
| 71 | #if defined(VGA_x86) |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 72 | # define VG_INSTR_PTR guest_EIP |
| 73 | # define VG_STACK_PTR guest_ESP |
| 74 | # define VG_FRAME_PTR guest_EBP |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 75 | #elif defined(VGA_amd64) |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 76 | # define VG_INSTR_PTR guest_RIP |
| 77 | # define VG_STACK_PTR guest_RSP |
| 78 | # define VG_FRAME_PTR guest_RBP |
cerion | 85665ca | 2005-06-20 15:51:07 +0000 | [diff] [blame] | 79 | #elif defined(VGA_ppc32) |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 80 | # define VG_INSTR_PTR guest_CIA |
| 81 | # define VG_STACK_PTR guest_GPR1 |
| 82 | # define VG_FRAME_PTR guest_GPR1 // No frame ptr for PPC |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 83 | #elif defined(VGA_ppc64) |
| 84 | # define VG_INSTR_PTR guest_CIA |
| 85 | # define VG_STACK_PTR guest_GPR1 |
| 86 | # define VG_FRAME_PTR guest_GPR1 // No frame ptr for PPC |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 87 | #else |
| 88 | # error Unknown arch |
| 89 | #endif |
| 90 | |
sewardj | 7821e2e | 2005-08-08 00:35:46 +0000 | [diff] [blame] | 91 | |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 92 | // Offsets for the Vex state |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 93 | #define VG_O_STACK_PTR (offsetof(VexGuestArchState, VG_STACK_PTR)) |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 94 | |
sewardj | 7821e2e | 2005-08-08 00:35:46 +0000 | [diff] [blame] | 95 | |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 96 | //------------------------------------------------------------- |
| 97 | /* Details about the capabilities of the underlying (host) CPU. These |
| 98 | details are acquired by (1) enquiring with the CPU at startup, or |
cerion | 1f0d814 | 2005-12-23 00:57:03 +0000 | [diff] [blame] | 99 | (2) from the AT_SYSINFO entries the kernel gave us (ppc cache |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 100 | line size). It's a bit nasty in the sense that there's no obvious |
| 101 | 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] | 102 | |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 103 | Current dependencies are: |
| 104 | |
| 105 | x86: initially: call VG_(machine_get_hwcaps) |
| 106 | |
| 107 | then safe to use VG_(machine_get_VexArchInfo) |
| 108 | and VG_(machine_x86_have_mxcsr) |
| 109 | ------------- |
| 110 | amd64: initially: call VG_(machine_get_hwcaps) |
| 111 | |
| 112 | then safe to use VG_(machine_get_VexArchInfo) |
| 113 | ------------- |
| 114 | ppc32: initially: call VG_(machine_get_hwcaps) |
| 115 | call VG_(machine_ppc32_set_clszB) |
| 116 | |
| 117 | then safe to use VG_(machine_get_VexArchInfo) |
sewardj | 2c36d42 | 2005-11-13 01:59:22 +0000 | [diff] [blame] | 118 | and VG_(machine_ppc32_has_FP) |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 119 | and VG_(machine_ppc32_has_VMX) |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 120 | ------------- |
| 121 | ppc64: initially: call VG_(machine_get_hwcaps) |
| 122 | call VG_(machine_ppc64_set_clszB) |
| 123 | |
| 124 | then safe to use VG_(machine_get_VexArchInfo) |
| 125 | and VG_(machine_ppc64_has_VMX) |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 126 | |
| 127 | VG_(machine_get_hwcaps) may use signals (although it attempts to |
| 128 | leave signal state unchanged) and therefore should only be |
| 129 | called before m_main sets up the client's signal state. |
| 130 | */ |
| 131 | |
| 132 | /* Determine what insn set and insn set variant the host has, and |
| 133 | record it. To be called once at system startup. Returns False if |
| 134 | this a CPU incapable of running Valgrind. */ |
| 135 | extern Bool VG_(machine_get_hwcaps)( void ); |
| 136 | |
| 137 | /* Fetch host cpu info, as per above comment. */ |
| 138 | extern void VG_(machine_get_VexArchInfo)( /*OUT*/VexArch*, |
| 139 | /*OUT*/VexArchInfo* ); |
| 140 | |
| 141 | /* Notify host cpu cache line size, as per above comment. */ |
cerion | bc28f66 | 2005-09-13 11:13:43 +0000 | [diff] [blame] | 142 | #if defined(VGA_ppc32) |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 143 | extern void VG_(machine_ppc32_set_clszB)( Int ); |
sewardj | 10f08cf | 2005-06-29 10:16:14 +0000 | [diff] [blame] | 144 | #endif |
| 145 | |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 146 | #if defined(VGA_ppc64) |
| 147 | extern void VG_(machine_ppc64_set_clszB)( Int ); |
| 148 | #endif |
| 149 | |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 150 | /* X86: set to 1 if the host is able to do {ld,st}mxcsr (load/store |
| 151 | the SSE control/status register), else zero. Is referenced from |
| 152 | assembly code, so do not change from a 32-bit int. */ |
sewardj | 7821e2e | 2005-08-08 00:35:46 +0000 | [diff] [blame] | 153 | #if defined(VGA_x86) |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 154 | extern UInt VG_(machine_x86_have_mxcsr); |
sewardj | 7821e2e | 2005-08-08 00:35:46 +0000 | [diff] [blame] | 155 | #endif |
| 156 | |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 157 | /* PPC32: set to 1 if FP instructions are supported in user-space, |
| 158 | else 0. Is referenced from assembly code, so do not change from a |
| 159 | 32-bit int. */ |
| 160 | #if defined(VGA_ppc32) |
sewardj | 2c36d42 | 2005-11-13 01:59:22 +0000 | [diff] [blame] | 161 | extern UInt VG_(machine_ppc32_has_FP); |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 162 | #endif |
| 163 | |
| 164 | /* PPC32: set to 1 if Altivec instructions are supported in |
| 165 | user-space, else 0. Is referenced from assembly code, so do not |
| 166 | change from a 32-bit int. */ |
| 167 | #if defined(VGA_ppc32) |
| 168 | extern UInt VG_(machine_ppc32_has_VMX); |
| 169 | #endif |
sewardj | 7821e2e | 2005-08-08 00:35:46 +0000 | [diff] [blame] | 170 | |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 171 | /* PPC64: set to 1 if Altivec instructions are supported in |
| 172 | user-space, else 0. Is referenced from assembly code, so do not |
| 173 | change from a 64-bit int. */ |
| 174 | #if defined(VGA_ppc64) |
| 175 | extern ULong VG_(machine_ppc64_has_VMX); |
| 176 | #endif |
| 177 | |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 178 | #endif // __PUB_CORE_MACHINE_H |
| 179 | |
| 180 | /*--------------------------------------------------------------------*/ |
| 181 | /*--- end ---*/ |
| 182 | /*--------------------------------------------------------------------*/ |