blob: a72381b033c9e074f0806106fd18c016286cea3f [file] [log] [blame]
njnf536bbb2005-06-13 04:21:38 +00001
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
sewardjb3a1e4b2015-08-21 11:32:26 +000010 Copyright (C) 2000-2015 Julian Seward
njnf536bbb2005-06-13 04:21:38 +000011 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"
florian535fb1b2013-09-15 13:54:34 +000041#include "pub_core_basics.h" // UnwindStartRegs
njnf536bbb2005-06-13 04:21:38 +000042
njn265aae72009-05-19 01:49:50 +000043// XXX: this is *really* the wrong spot for these things
sewardj8eb8bab2015-07-21 14:44:28 +000044#if defined(VGP_x86_linux) || defined(VGP_x86_solaris)
sewardj6e340c72005-07-10 00:53:42 +000045# define VG_ELF_DATA2XXX ELFDATA2LSB
njnaf839f52005-06-23 03:27:57 +000046# define VG_ELF_MACHINE EM_386
47# define VG_ELF_CLASS ELFCLASS32
sewardjf1c91e02006-10-17 01:35:58 +000048# undef VG_PLAT_USES_PPCTOC
sewardj8eb8bab2015-07-21 14:44:28 +000049#elif defined(VGP_amd64_linux) || defined(VGP_amd64_solaris)
sewardj6e340c72005-07-10 00:53:42 +000050# define VG_ELF_DATA2XXX ELFDATA2LSB
njnaf839f52005-06-23 03:27:57 +000051# define VG_ELF_MACHINE EM_X86_64
52# define VG_ELF_CLASS ELFCLASS64
sewardjf1c91e02006-10-17 01:35:58 +000053# undef VG_PLAT_USES_PPCTOC
54#elif defined(VGP_ppc32_linux)
sewardj6e340c72005-07-10 00:53:42 +000055# define VG_ELF_DATA2XXX ELFDATA2MSB
njnaf839f52005-06-23 03:27:57 +000056# define VG_ELF_MACHINE EM_PPC
57# define VG_ELF_CLASS ELFCLASS32
sewardjf1c91e02006-10-17 01:35:58 +000058# undef VG_PLAT_USES_PPCTOC
carllcae0cc22014-08-07 23:17:29 +000059#elif defined(VGP_ppc64be_linux)
sewardj2c48c7b2005-11-29 13:05:56 +000060# define VG_ELF_DATA2XXX ELFDATA2MSB
61# define VG_ELF_MACHINE EM_PPC64
62# define VG_ELF_CLASS ELFCLASS64
sewardjf1c91e02006-10-17 01:35:58 +000063# define VG_PLAT_USES_PPCTOC 1
carll582d5822014-08-07 23:35:54 +000064#elif defined(VGP_ppc64le_linux)
65# define VG_ELF_DATA2XXX ELFDATA2LSB
66# define VG_ELF_MACHINE EM_PPC64
67# define VG_ELF_CLASS ELFCLASS64
68# undef VG_PLAT_USES_PPCTOC
sewardj59570ff2010-01-01 11:59:33 +000069#elif defined(VGP_arm_linux)
70# define VG_ELF_DATA2XXX ELFDATA2LSB
71# define VG_ELF_MACHINE EM_ARM
72# define VG_ELF_CLASS ELFCLASS32
73# undef VG_PLAT_USES_PPCTOC
sewardjf0c12502014-01-12 12:54:00 +000074#elif defined(VGP_arm64_linux)
75# define VG_ELF_DATA2XXX ELFDATA2LSB
76# define VG_ELF_MACHINE EM_AARCH64
77# define VG_ELF_CLASS ELFCLASS64
78# undef VG_PLAT_USES_PPCTOC
njnf76d27a2009-05-28 01:53:07 +000079#elif defined(VGO_darwin)
80# undef VG_ELF_DATA2XXX
81# undef VG_ELF_MACHINE
82# undef VG_ELF_CLASS
83# undef VG_PLAT_USES_PPCTOC
sewardjb5b87402011-03-07 16:05:35 +000084#elif defined(VGP_s390x_linux)
85# define VG_ELF_DATA2XXX ELFDATA2MSB
86# define VG_ELF_MACHINE EM_S390
87# define VG_ELF_CLASS ELFCLASS64
88# undef VG_PLAT_USES_PPCTOC
sewardj5db15402012-06-07 09:13:21 +000089#elif defined(VGP_mips32_linux)
90# if defined (VG_LITTLEENDIAN)
91# define VG_ELF_DATA2XXX ELFDATA2LSB
92# elif defined (VG_BIGENDIAN)
93# define VG_ELF_DATA2XXX ELFDATA2MSB
94# else
95# error "Unknown endianness"
96# endif
97# define VG_ELF_MACHINE EM_MIPS
98# define VG_ELF_CLASS ELFCLASS32
99# undef VG_PLAT_USES_PPCTOC
petarj4df0bfc2013-02-27 23:17:33 +0000100#elif defined(VGP_mips64_linux)
101# if defined (VG_LITTLEENDIAN)
102# define VG_ELF_DATA2XXX ELFDATA2LSB
103# elif defined (VG_BIGENDIAN)
104# define VG_ELF_DATA2XXX ELFDATA2MSB
105# else
106# error "Unknown endianness"
107# endif
108# define VG_ELF_MACHINE EM_MIPS
109# define VG_ELF_CLASS ELFCLASS64
110# undef VG_PLAT_USES_PPCTOC
sewardj112711a2015-04-10 12:30:09 +0000111#elif defined(VGP_tilegx_linux)
112# define VG_ELF_DATA2XXX ELFDATA2LSB
113 #ifndef EM_TILEGX
114 #define EM_TILEGX 191
115 #endif
116# define VG_ELF_MACHINE EM_TILEGX
117# define VG_ELF_CLASS ELFCLASS64
118# undef VG_PLAT_USES_PPCTOC
njnf536bbb2005-06-13 04:21:38 +0000119#else
sewardjf1c91e02006-10-17 01:35:58 +0000120# error Unknown platform
njnf536bbb2005-06-13 04:21:38 +0000121#endif
122
123#if defined(VGA_x86)
njnaf839f52005-06-23 03:27:57 +0000124# define VG_INSTR_PTR guest_EIP
125# define VG_STACK_PTR guest_ESP
126# define VG_FRAME_PTR guest_EBP
njnf536bbb2005-06-13 04:21:38 +0000127#elif defined(VGA_amd64)
njnaf839f52005-06-23 03:27:57 +0000128# define VG_INSTR_PTR guest_RIP
129# define VG_STACK_PTR guest_RSP
130# define VG_FRAME_PTR guest_RBP
cerion85665ca2005-06-20 15:51:07 +0000131#elif defined(VGA_ppc32)
njnaf839f52005-06-23 03:27:57 +0000132# define VG_INSTR_PTR guest_CIA
133# define VG_STACK_PTR guest_GPR1
134# define VG_FRAME_PTR guest_GPR1 // No frame ptr for PPC
carllcae0cc22014-08-07 23:17:29 +0000135#elif defined(VGA_ppc64be) || defined(VGA_ppc64le)
sewardj2c48c7b2005-11-29 13:05:56 +0000136# define VG_INSTR_PTR guest_CIA
137# define VG_STACK_PTR guest_GPR1
138# define VG_FRAME_PTR guest_GPR1 // No frame ptr for PPC
sewardj59570ff2010-01-01 11:59:33 +0000139#elif defined(VGA_arm)
sewardj1dbd3372010-08-22 12:21:14 +0000140# define VG_INSTR_PTR guest_R15T
sewardj59570ff2010-01-01 11:59:33 +0000141# define VG_STACK_PTR guest_R13
142# define VG_FRAME_PTR guest_R11
sewardjf0c12502014-01-12 12:54:00 +0000143#elif defined(VGA_arm64)
144# define VG_INSTR_PTR guest_PC
sewardj03451882014-01-15 10:25:55 +0000145# define VG_STACK_PTR guest_XSP
146# define VG_FRAME_PTR guest_X29 // FIXME: is this right?
sewardjb5b87402011-03-07 16:05:35 +0000147#elif defined(VGA_s390x)
148# define VG_INSTR_PTR guest_IA
149# define VG_STACK_PTR guest_SP
150# define VG_FRAME_PTR guest_FP
florianccb843b2012-02-26 17:51:28 +0000151# define VG_FPC_REG guest_fpc
sewardj5db15402012-06-07 09:13:21 +0000152#elif defined(VGA_mips32)
153# define VG_INSTR_PTR guest_PC
154# define VG_STACK_PTR guest_r29
155# define VG_FRAME_PTR guest_r30
petarj4df0bfc2013-02-27 23:17:33 +0000156#elif defined(VGA_mips64)
157# define VG_INSTR_PTR guest_PC
158# define VG_STACK_PTR guest_r29
159# define VG_FRAME_PTR guest_r30
sewardj112711a2015-04-10 12:30:09 +0000160#elif defined(VGA_tilegx)
161# define VG_INSTR_PTR guest_pc
162# define VG_STACK_PTR guest_r54
163# define VG_FRAME_PTR guest_r52
njnf536bbb2005-06-13 04:21:38 +0000164#else
165# error Unknown arch
166#endif
167
sewardj7821e2e2005-08-08 00:35:46 +0000168
njnf536bbb2005-06-13 04:21:38 +0000169// Offsets for the Vex state
njnaf839f52005-06-23 03:27:57 +0000170#define VG_O_STACK_PTR (offsetof(VexGuestArchState, VG_STACK_PTR))
njncda2f0f2009-05-18 02:12:08 +0000171#define VG_O_INSTR_PTR (offsetof(VexGuestArchState, VG_INSTR_PTR))
sewardj8eb8bab2015-07-21 14:44:28 +0000172#define VG_O_FRAME_PTR (offsetof(VexGuestArchState, VG_FRAME_PTR))
florianccb843b2012-02-26 17:51:28 +0000173#define VG_O_FPC_REG (offsetof(VexGuestArchState, VG_FPC_REG))
njnf536bbb2005-06-13 04:21:38 +0000174
sewardj7821e2e2005-08-08 00:35:46 +0000175
sewardje2d1e672005-11-12 23:10:48 +0000176//-------------------------------------------------------------
sewardj1dbd3372010-08-22 12:21:14 +0000177// Guest state accessors that are not visible to tools. The only
178// ones that are visible are get_IP and get_SP.
179
180//Addr VG_(get_IP) ( ThreadId tid ); // in pub_tool_machine.h
181//Addr VG_(get_SP) ( ThreadId tid ); // in pub_tool_machine.h
182Addr VG_(get_FP) ( ThreadId tid );
183
184void VG_(set_IP) ( ThreadId tid, Addr encip );
185void VG_(set_SP) ( ThreadId tid, Addr sp );
186
187
188//-------------------------------------------------------------
sewardj59570ff2010-01-01 11:59:33 +0000189// Get hold of the values needed for a stack unwind, for the specified
190// (client) thread.
191void VG_(get_UnwindStartRegs) ( /*OUT*/UnwindStartRegs* regs,
192 ThreadId tid );
193
194
195//-------------------------------------------------------------
sewardje2d1e672005-11-12 23:10:48 +0000196/* Details about the capabilities of the underlying (host) CPU. These
197 details are acquired by (1) enquiring with the CPU at startup, or
cerion1f0d8142005-12-23 00:57:03 +0000198 (2) from the AT_SYSINFO entries the kernel gave us (ppc cache
sewardje2d1e672005-11-12 23:10:48 +0000199 line size). It's a bit nasty in the sense that there's no obvious
200 way to stop uses of some of this info before it's ready to go.
sewardj10f08cf2005-06-29 10:16:14 +0000201
sewardje2d1e672005-11-12 23:10:48 +0000202 Current dependencies are:
203
204 x86: initially: call VG_(machine_get_hwcaps)
205
206 then safe to use VG_(machine_get_VexArchInfo)
207 and VG_(machine_x86_have_mxcsr)
208 -------------
209 amd64: initially: call VG_(machine_get_hwcaps)
210
211 then safe to use VG_(machine_get_VexArchInfo)
212 -------------
213 ppc32: initially: call VG_(machine_get_hwcaps)
214 call VG_(machine_ppc32_set_clszB)
215
216 then safe to use VG_(machine_get_VexArchInfo)
sewardj2c36d422005-11-13 01:59:22 +0000217 and VG_(machine_ppc32_has_FP)
sewardje2d1e672005-11-12 23:10:48 +0000218 and VG_(machine_ppc32_has_VMX)
sewardj2c48c7b2005-11-29 13:05:56 +0000219 -------------
220 ppc64: initially: call VG_(machine_get_hwcaps)
221 call VG_(machine_ppc64_set_clszB)
222
223 then safe to use VG_(machine_get_VexArchInfo)
224 and VG_(machine_ppc64_has_VMX)
sewardja3551be2010-09-09 07:25:58 +0000225 -------------
226 arm: initially: call VG_(machine_get_hwcaps)
227 call VG_(machine_arm_set_has_NEON)
228
229 then safe to use VG_(machine_get_VexArchInfo)
florian0daa4e32012-04-22 02:48:20 +0000230 -------------
231 s390x: initially: call VG_(machine_get_hwcaps)
232
233 then safe to use VG_(machine_get_VexArchInfo)
sewardje2d1e672005-11-12 23:10:48 +0000234
235 VG_(machine_get_hwcaps) may use signals (although it attempts to
236 leave signal state unchanged) and therefore should only be
237 called before m_main sets up the client's signal state.
238*/
239
240/* Determine what insn set and insn set variant the host has, and
241 record it. To be called once at system startup. Returns False if
242 this a CPU incapable of running Valgrind. */
243extern Bool VG_(machine_get_hwcaps)( void );
244
florian78627012012-10-07 19:47:04 +0000245/* Determine information about the cache system this host has and
246 record it. Returns False, if cache information cannot be auto-detected. */
247extern Bool VG_(machine_get_cache_info)( VexArchInfo * );
sewardje2d1e672005-11-12 23:10:48 +0000248
249/* Notify host cpu cache line size, as per above comment. */
cerionbc28f662005-09-13 11:13:43 +0000250#if defined(VGA_ppc32)
sewardje2d1e672005-11-12 23:10:48 +0000251extern void VG_(machine_ppc32_set_clszB)( Int );
sewardj10f08cf2005-06-29 10:16:14 +0000252#endif
253
carllcae0cc22014-08-07 23:17:29 +0000254#if defined(VGA_ppc64be) || defined(VGA_ppc64le)
sewardj2c48c7b2005-11-29 13:05:56 +0000255extern void VG_(machine_ppc64_set_clszB)( Int );
256#endif
257
sewardja3551be2010-09-09 07:25:58 +0000258#if defined(VGA_arm)
259extern void VG_(machine_arm_set_has_NEON)( Bool );
260#endif
261
sewardje2d1e672005-11-12 23:10:48 +0000262/* X86: set to 1 if the host is able to do {ld,st}mxcsr (load/store
263 the SSE control/status register), else zero. Is referenced from
264 assembly code, so do not change from a 32-bit int. */
sewardj7821e2e2005-08-08 00:35:46 +0000265#if defined(VGA_x86)
sewardje2d1e672005-11-12 23:10:48 +0000266extern UInt VG_(machine_x86_have_mxcsr);
sewardj7821e2e2005-08-08 00:35:46 +0000267#endif
268
sewardje2d1e672005-11-12 23:10:48 +0000269/* PPC32: set to 1 if FP instructions are supported in user-space,
270 else 0. Is referenced from assembly code, so do not change from a
271 32-bit int. */
272#if defined(VGA_ppc32)
sewardj2c36d422005-11-13 01:59:22 +0000273extern UInt VG_(machine_ppc32_has_FP);
sewardje2d1e672005-11-12 23:10:48 +0000274#endif
275
276/* PPC32: set to 1 if Altivec instructions are supported in
277 user-space, else 0. Is referenced from assembly code, so do not
278 change from a 32-bit int. */
279#if defined(VGA_ppc32)
280extern UInt VG_(machine_ppc32_has_VMX);
281#endif
sewardj7821e2e2005-08-08 00:35:46 +0000282
sewardj2c48c7b2005-11-29 13:05:56 +0000283/* PPC64: set to 1 if Altivec instructions are supported in
284 user-space, else 0. Is referenced from assembly code, so do not
285 change from a 64-bit int. */
carllcae0cc22014-08-07 23:17:29 +0000286#if defined(VGA_ppc64be) || defined(VGA_ppc64le)
sewardj2c48c7b2005-11-29 13:05:56 +0000287extern ULong VG_(machine_ppc64_has_VMX);
288#endif
289
sewardj1dbd3372010-08-22 12:21:14 +0000290#if defined(VGA_arm)
291extern Int VG_(machine_arm_archlevel);
292#endif
293
njnf536bbb2005-06-13 04:21:38 +0000294#endif // __PUB_CORE_MACHINE_H
295
296/*--------------------------------------------------------------------*/
297/*--- end ---*/
298/*--------------------------------------------------------------------*/