pub_core_machine.h revision 8f943afc22a6a683b78271836c8ddc462b4824a9
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
10   Copyright (C) 2000-2011 Julian Seward
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
42// XXX: this is *really* the wrong spot for these things
43#if defined(VGP_x86_linux)
44#  define VG_ELF_DATA2XXX     ELFDATA2LSB
45#  define VG_ELF_MACHINE      EM_386
46#  define VG_ELF_CLASS        ELFCLASS32
47#  undef  VG_PLAT_USES_PPCTOC
48#elif defined(VGP_amd64_linux)
49#  define VG_ELF_DATA2XXX     ELFDATA2LSB
50#  define VG_ELF_MACHINE      EM_X86_64
51#  define VG_ELF_CLASS        ELFCLASS64
52#  undef  VG_PLAT_USES_PPCTOC
53#elif defined(VGP_ppc32_linux)
54#  define VG_ELF_DATA2XXX     ELFDATA2MSB
55#  define VG_ELF_MACHINE      EM_PPC
56#  define VG_ELF_CLASS        ELFCLASS32
57#  undef  VG_PLAT_USES_PPCTOC
58#elif defined(VGP_ppc64_linux)
59#  define VG_ELF_DATA2XXX     ELFDATA2MSB
60#  define VG_ELF_MACHINE      EM_PPC64
61#  define VG_ELF_CLASS        ELFCLASS64
62#  define VG_PLAT_USES_PPCTOC 1
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
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
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
78#else
79#  error Unknown platform
80#endif
81
82#if defined(VGA_x86)
83#  define VG_INSTR_PTR        guest_EIP
84#  define VG_STACK_PTR        guest_ESP
85#  define VG_FRAME_PTR        guest_EBP
86#elif defined(VGA_amd64)
87#  define VG_INSTR_PTR        guest_RIP
88#  define VG_STACK_PTR        guest_RSP
89#  define VG_FRAME_PTR        guest_RBP
90#elif defined(VGA_ppc32)
91#  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
94#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
98#elif defined(VGA_arm)
99#  define VG_INSTR_PTR        guest_R15T
100#  define VG_STACK_PTR        guest_R13
101#  define VG_FRAME_PTR        guest_R11
102#elif defined(VGA_s390x)
103#  define VG_INSTR_PTR        guest_IA
104#  define VG_STACK_PTR        guest_SP
105#  define VG_FRAME_PTR        guest_FP
106#else
107#  error Unknown arch
108#endif
109
110
111// Offsets for the Vex state
112#define VG_O_STACK_PTR        (offsetof(VexGuestArchState, VG_STACK_PTR))
113#define VG_O_INSTR_PTR        (offsetof(VexGuestArchState, VG_INSTR_PTR))
114
115
116//-------------------------------------------------------------
117// Guest state accessors that are not visible to tools.  The only
118// ones that are visible are get_IP and get_SP.
119
120//Addr VG_(get_IP) ( ThreadId tid );  // in pub_tool_machine.h
121//Addr VG_(get_SP) ( ThreadId tid );  // in pub_tool_machine.h
122Addr VG_(get_FP) ( ThreadId tid );
123
124void VG_(set_IP) ( ThreadId tid, Addr encip );
125void VG_(set_SP) ( ThreadId tid, Addr sp );
126
127
128//-------------------------------------------------------------
129// Get hold of the values needed for a stack unwind, for the specified
130// (client) thread.
131void VG_(get_UnwindStartRegs) ( /*OUT*/UnwindStartRegs* regs,
132                                ThreadId tid );
133
134
135//-------------------------------------------------------------
136/* Details about the capabilities of the underlying (host) CPU.  These
137   details are acquired by (1) enquiring with the CPU at startup, or
138   (2) from the AT_SYSINFO entries the kernel gave us (ppc cache
139   line size).  It's a bit nasty in the sense that there's no obvious
140   way to stop uses of some of this info before it's ready to go.
141
142   Current dependencies are:
143
144   x86:   initially:  call VG_(machine_get_hwcaps)
145
146          then safe to use VG_(machine_get_VexArchInfo)
147                       and VG_(machine_x86_have_mxcsr)
148   -------------
149   amd64: initially:  call VG_(machine_get_hwcaps)
150
151          then safe to use VG_(machine_get_VexArchInfo)
152   -------------
153   ppc32: initially:  call VG_(machine_get_hwcaps)
154                      call VG_(machine_ppc32_set_clszB)
155
156          then safe to use VG_(machine_get_VexArchInfo)
157                       and VG_(machine_ppc32_has_FP)
158                       and VG_(machine_ppc32_has_VMX)
159   -------------
160   ppc64: initially:  call VG_(machine_get_hwcaps)
161                      call VG_(machine_ppc64_set_clszB)
162
163          then safe to use VG_(machine_get_VexArchInfo)
164                       and VG_(machine_ppc64_has_VMX)
165   -------------
166   arm:   initially:  call VG_(machine_get_hwcaps)
167                      call VG_(machine_arm_set_has_NEON)
168
169          then safe to use VG_(machine_get_VexArchInfo)
170
171   VG_(machine_get_hwcaps) may use signals (although it attempts to
172   leave signal state unchanged) and therefore should only be
173   called before m_main sets up the client's signal state.
174*/
175
176/* Determine what insn set and insn set variant the host has, and
177   record it.  To be called once at system startup.  Returns False if
178   this a CPU incapable of running Valgrind. */
179extern Bool VG_(machine_get_hwcaps)( void );
180
181/* Fetch host cpu info, as per above comment. */
182extern void VG_(machine_get_VexArchInfo)( /*OUT*/VexArch*,
183                                          /*OUT*/VexArchInfo* );
184
185/* Notify host cpu cache line size, as per above comment. */
186#if defined(VGA_ppc32)
187extern void VG_(machine_ppc32_set_clszB)( Int );
188#endif
189
190#if defined(VGA_ppc64)
191extern void VG_(machine_ppc64_set_clszB)( Int );
192#endif
193
194#if defined(VGA_arm)
195extern void VG_(machine_arm_set_has_NEON)( Bool );
196#endif
197
198/* X86: set to 1 if the host is able to do {ld,st}mxcsr (load/store
199   the SSE control/status register), else zero.  Is referenced from
200   assembly code, so do not change from a 32-bit int. */
201#if defined(VGA_x86)
202extern UInt VG_(machine_x86_have_mxcsr);
203#endif
204
205/* PPC32: set to 1 if FP instructions are supported in user-space,
206   else 0.  Is referenced from assembly code, so do not change from a
207   32-bit int. */
208#if defined(VGA_ppc32)
209extern UInt VG_(machine_ppc32_has_FP);
210#endif
211
212/* PPC32: set to 1 if Altivec instructions are supported in
213   user-space, else 0.  Is referenced from assembly code, so do not
214   change from a 32-bit int. */
215#if defined(VGA_ppc32)
216extern UInt VG_(machine_ppc32_has_VMX);
217#endif
218
219/* PPC64: set to 1 if Altivec instructions are supported in
220   user-space, else 0.  Is referenced from assembly code, so do not
221   change from a 64-bit int. */
222#if defined(VGA_ppc64)
223extern ULong VG_(machine_ppc64_has_VMX);
224#endif
225
226#if defined(VGA_arm)
227extern Int VG_(machine_arm_archlevel);
228#endif
229
230#endif   // __PUB_CORE_MACHINE_H
231
232/*--------------------------------------------------------------------*/
233/*--- end                                                          ---*/
234/*--------------------------------------------------------------------*/
235