blob: ea32dc83d09862ba97217c5a1efd0e7664b2bf54 [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
sewardj9eecbbb2010-05-03 21:37:12 +000010 Copyright (C) 2000-2010 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"
41
njn265aae72009-05-19 01:49:50 +000042// XXX: this is *really* the wrong spot for these things
sewardjf1c91e02006-10-17 01:35:58 +000043#if defined(VGP_x86_linux)
sewardj6e340c72005-07-10 00:53:42 +000044# define VG_ELF_DATA2XXX ELFDATA2LSB
njnaf839f52005-06-23 03:27:57 +000045# define VG_ELF_MACHINE EM_386
46# define VG_ELF_CLASS ELFCLASS32
sewardjf1c91e02006-10-17 01:35:58 +000047# undef VG_PLAT_USES_PPCTOC
48#elif defined(VGP_amd64_linux)
sewardj6e340c72005-07-10 00:53:42 +000049# define VG_ELF_DATA2XXX ELFDATA2LSB
njnaf839f52005-06-23 03:27:57 +000050# define VG_ELF_MACHINE EM_X86_64
51# define VG_ELF_CLASS ELFCLASS64
sewardjf1c91e02006-10-17 01:35:58 +000052# undef VG_PLAT_USES_PPCTOC
53#elif defined(VGP_ppc32_linux)
sewardj6e340c72005-07-10 00:53:42 +000054# define VG_ELF_DATA2XXX ELFDATA2MSB
njnaf839f52005-06-23 03:27:57 +000055# define VG_ELF_MACHINE EM_PPC
56# define VG_ELF_CLASS ELFCLASS32
sewardjf1c91e02006-10-17 01:35:58 +000057# undef VG_PLAT_USES_PPCTOC
58#elif defined(VGP_ppc64_linux)
sewardj2c48c7b2005-11-29 13:05:56 +000059# define VG_ELF_DATA2XXX ELFDATA2MSB
60# define VG_ELF_MACHINE EM_PPC64
61# define VG_ELF_CLASS ELFCLASS64
sewardjf1c91e02006-10-17 01:35:58 +000062# define VG_PLAT_USES_PPCTOC 1
sewardj59570ff2010-01-01 11:59:33 +000063#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
sewardjf1c91e02006-10-17 01:35:58 +000068#elif defined(VGO_aix5)
69# undef VG_ELF_DATA2XXX
70# undef VG_ELF_MACHINE
71# undef VG_ELF_CLASS
72# define VG_PLAT_USES_PPCTOC 1
njnf76d27a2009-05-28 01:53:07 +000073#elif defined(VGO_darwin)
74# undef VG_ELF_DATA2XXX
75# undef VG_ELF_MACHINE
76# undef VG_ELF_CLASS
77# undef VG_PLAT_USES_PPCTOC
njnf536bbb2005-06-13 04:21:38 +000078#else
sewardjf1c91e02006-10-17 01:35:58 +000079# error Unknown platform
njnf536bbb2005-06-13 04:21:38 +000080#endif
81
82#if defined(VGA_x86)
njnaf839f52005-06-23 03:27:57 +000083# define VG_INSTR_PTR guest_EIP
84# define VG_STACK_PTR guest_ESP
85# define VG_FRAME_PTR guest_EBP
njnf536bbb2005-06-13 04:21:38 +000086#elif defined(VGA_amd64)
njnaf839f52005-06-23 03:27:57 +000087# define VG_INSTR_PTR guest_RIP
88# define VG_STACK_PTR guest_RSP
89# define VG_FRAME_PTR guest_RBP
cerion85665ca2005-06-20 15:51:07 +000090#elif defined(VGA_ppc32)
njnaf839f52005-06-23 03:27:57 +000091# define VG_INSTR_PTR guest_CIA
92# define VG_STACK_PTR guest_GPR1
93# define VG_FRAME_PTR guest_GPR1 // No frame ptr for PPC
sewardj2c48c7b2005-11-29 13:05:56 +000094#elif defined(VGA_ppc64)
95# define VG_INSTR_PTR guest_CIA
96# define VG_STACK_PTR guest_GPR1
97# define VG_FRAME_PTR guest_GPR1 // No frame ptr for PPC
sewardj59570ff2010-01-01 11:59:33 +000098#elif defined(VGA_arm)
sewardj1dbd3372010-08-22 12:21:14 +000099# define VG_INSTR_PTR guest_R15T
sewardj59570ff2010-01-01 11:59:33 +0000100# define VG_STACK_PTR guest_R13
101# define VG_FRAME_PTR guest_R11
njnf536bbb2005-06-13 04:21:38 +0000102#else
103# error Unknown arch
104#endif
105
sewardj7821e2e2005-08-08 00:35:46 +0000106
njnf536bbb2005-06-13 04:21:38 +0000107// Offsets for the Vex state
njnaf839f52005-06-23 03:27:57 +0000108#define VG_O_STACK_PTR (offsetof(VexGuestArchState, VG_STACK_PTR))
njncda2f0f2009-05-18 02:12:08 +0000109#define VG_O_INSTR_PTR (offsetof(VexGuestArchState, VG_INSTR_PTR))
njnf536bbb2005-06-13 04:21:38 +0000110
sewardj7821e2e2005-08-08 00:35:46 +0000111
sewardje2d1e672005-11-12 23:10:48 +0000112//-------------------------------------------------------------
sewardj1dbd3372010-08-22 12:21:14 +0000113// Guest state accessors that are not visible to tools. The only
114// ones that are visible are get_IP and get_SP.
115
116//Addr VG_(get_IP) ( ThreadId tid ); // in pub_tool_machine.h
117//Addr VG_(get_SP) ( ThreadId tid ); // in pub_tool_machine.h
118Addr VG_(get_FP) ( ThreadId tid );
119
120void VG_(set_IP) ( ThreadId tid, Addr encip );
121void VG_(set_SP) ( ThreadId tid, Addr sp );
122
123
124//-------------------------------------------------------------
sewardj59570ff2010-01-01 11:59:33 +0000125// Get hold of the values needed for a stack unwind, for the specified
126// (client) thread.
127void VG_(get_UnwindStartRegs) ( /*OUT*/UnwindStartRegs* regs,
128 ThreadId tid );
129
130
131//-------------------------------------------------------------
sewardje2d1e672005-11-12 23:10:48 +0000132/* Details about the capabilities of the underlying (host) CPU. These
133 details are acquired by (1) enquiring with the CPU at startup, or
cerion1f0d8142005-12-23 00:57:03 +0000134 (2) from the AT_SYSINFO entries the kernel gave us (ppc cache
sewardje2d1e672005-11-12 23:10:48 +0000135 line size). It's a bit nasty in the sense that there's no obvious
136 way to stop uses of some of this info before it's ready to go.
sewardj10f08cf2005-06-29 10:16:14 +0000137
sewardje2d1e672005-11-12 23:10:48 +0000138 Current dependencies are:
139
140 x86: initially: call VG_(machine_get_hwcaps)
141
142 then safe to use VG_(machine_get_VexArchInfo)
143 and VG_(machine_x86_have_mxcsr)
144 -------------
145 amd64: initially: call VG_(machine_get_hwcaps)
146
147 then safe to use VG_(machine_get_VexArchInfo)
148 -------------
149 ppc32: initially: call VG_(machine_get_hwcaps)
150 call VG_(machine_ppc32_set_clszB)
151
152 then safe to use VG_(machine_get_VexArchInfo)
sewardj2c36d422005-11-13 01:59:22 +0000153 and VG_(machine_ppc32_has_FP)
sewardje2d1e672005-11-12 23:10:48 +0000154 and VG_(machine_ppc32_has_VMX)
sewardj2c48c7b2005-11-29 13:05:56 +0000155 -------------
156 ppc64: initially: call VG_(machine_get_hwcaps)
157 call VG_(machine_ppc64_set_clszB)
158
159 then safe to use VG_(machine_get_VexArchInfo)
160 and VG_(machine_ppc64_has_VMX)
sewardja3551be2010-09-09 07:25:58 +0000161 -------------
162 arm: initially: call VG_(machine_get_hwcaps)
163 call VG_(machine_arm_set_has_NEON)
164
165 then safe to use VG_(machine_get_VexArchInfo)
sewardje2d1e672005-11-12 23:10:48 +0000166
167 VG_(machine_get_hwcaps) may use signals (although it attempts to
168 leave signal state unchanged) and therefore should only be
169 called before m_main sets up the client's signal state.
170*/
171
172/* Determine what insn set and insn set variant the host has, and
173 record it. To be called once at system startup. Returns False if
174 this a CPU incapable of running Valgrind. */
175extern Bool VG_(machine_get_hwcaps)( void );
176
177/* Fetch host cpu info, as per above comment. */
178extern void VG_(machine_get_VexArchInfo)( /*OUT*/VexArch*,
179 /*OUT*/VexArchInfo* );
180
181/* Notify host cpu cache line size, as per above comment. */
cerionbc28f662005-09-13 11:13:43 +0000182#if defined(VGA_ppc32)
sewardje2d1e672005-11-12 23:10:48 +0000183extern void VG_(machine_ppc32_set_clszB)( Int );
sewardj10f08cf2005-06-29 10:16:14 +0000184#endif
185
sewardj2c48c7b2005-11-29 13:05:56 +0000186#if defined(VGA_ppc64)
187extern void VG_(machine_ppc64_set_clszB)( Int );
188#endif
189
sewardja3551be2010-09-09 07:25:58 +0000190#if defined(VGA_arm)
191extern void VG_(machine_arm_set_has_NEON)( Bool );
192#endif
193
sewardje2d1e672005-11-12 23:10:48 +0000194/* X86: set to 1 if the host is able to do {ld,st}mxcsr (load/store
195 the SSE control/status register), else zero. Is referenced from
196 assembly code, so do not change from a 32-bit int. */
sewardj7821e2e2005-08-08 00:35:46 +0000197#if defined(VGA_x86)
sewardje2d1e672005-11-12 23:10:48 +0000198extern UInt VG_(machine_x86_have_mxcsr);
sewardj7821e2e2005-08-08 00:35:46 +0000199#endif
200
sewardje2d1e672005-11-12 23:10:48 +0000201/* PPC32: set to 1 if FP instructions are supported in user-space,
202 else 0. Is referenced from assembly code, so do not change from a
203 32-bit int. */
204#if defined(VGA_ppc32)
sewardj2c36d422005-11-13 01:59:22 +0000205extern UInt VG_(machine_ppc32_has_FP);
sewardje2d1e672005-11-12 23:10:48 +0000206#endif
207
208/* PPC32: set to 1 if Altivec instructions are supported in
209 user-space, else 0. Is referenced from assembly code, so do not
210 change from a 32-bit int. */
211#if defined(VGA_ppc32)
212extern UInt VG_(machine_ppc32_has_VMX);
213#endif
sewardj7821e2e2005-08-08 00:35:46 +0000214
sewardj2c48c7b2005-11-29 13:05:56 +0000215/* PPC64: set to 1 if Altivec instructions are supported in
216 user-space, else 0. Is referenced from assembly code, so do not
217 change from a 64-bit int. */
218#if defined(VGA_ppc64)
219extern ULong VG_(machine_ppc64_has_VMX);
220#endif
221
sewardj1dbd3372010-08-22 12:21:14 +0000222#if defined(VGA_arm)
223extern Int VG_(machine_arm_archlevel);
224#endif
225
njnf536bbb2005-06-13 04:21:38 +0000226#endif // __PUB_CORE_MACHINE_H
227
228/*--------------------------------------------------------------------*/
229/*--- end ---*/
230/*--------------------------------------------------------------------*/