2 /*--------------------------------------------------------------------*/
3 /*--- Machine-related things. pub_core_machine.h ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2000-2010 Julian Seward
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.
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.
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
28 The GNU General Public License is contained in the file COPYING.
31 #ifndef __PUB_CORE_MACHINE_H
32 #define __PUB_CORE_MACHINE_H
34 //--------------------------------------------------------------------
35 // PURPOSE: This module contains code related to the particular
36 // architecture, things like accessing guest state, endianness, word size,
38 //--------------------------------------------------------------------
40 #include "pub_tool_machine.h"
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_aix5)
69 # undef VG_ELF_DATA2XXX
70 # undef VG_ELF_MACHINE
72 # define VG_PLAT_USES_PPCTOC 1
73 #elif defined(VGO_darwin)
74 # undef VG_ELF_DATA2XXX
75 # undef VG_ELF_MACHINE
77 # undef VG_PLAT_USES_PPCTOC
78 #elif defined(VGO_l4re)
79 # define VG_ELF_DATA2XXX ELFDATA2LSB
80 # define VG_ELF_MACHINE EM_386
81 # define VG_ELF_CLASS ELFCLASS32
82 # undef VG_PLAT_USES_PPCTOC
84 # error Unknown platform
88 # define VG_INSTR_PTR guest_EIP
89 # define VG_STACK_PTR guest_ESP
90 # define VG_FRAME_PTR guest_EBP
91 #elif defined(VGA_amd64)
92 # define VG_INSTR_PTR guest_RIP
93 # define VG_STACK_PTR guest_RSP
94 # define VG_FRAME_PTR guest_RBP
95 #elif defined(VGA_ppc32)
96 # define VG_INSTR_PTR guest_CIA
97 # define VG_STACK_PTR guest_GPR1
98 # define VG_FRAME_PTR guest_GPR1 // No frame ptr for PPC
99 #elif defined(VGA_ppc64)
100 # define VG_INSTR_PTR guest_CIA
101 # define VG_STACK_PTR guest_GPR1
102 # define VG_FRAME_PTR guest_GPR1 // No frame ptr for PPC
103 #elif defined(VGA_arm)
104 # define VG_INSTR_PTR guest_R15
105 # define VG_STACK_PTR guest_R13
106 # define VG_FRAME_PTR guest_R11
112 // Offsets for the Vex state
113 #define VG_O_STACK_PTR (offsetof(VexGuestArchState, VG_STACK_PTR))
114 #define VG_O_INSTR_PTR (offsetof(VexGuestArchState, VG_INSTR_PTR))
117 //-------------------------------------------------------------
118 // Get hold of the values needed for a stack unwind, for the specified
120 void VG_(get_UnwindStartRegs) ( /*OUT*/UnwindStartRegs* regs,
124 //-------------------------------------------------------------
125 /* Details about the capabilities of the underlying (host) CPU. These
126 details are acquired by (1) enquiring with the CPU at startup, or
127 (2) from the AT_SYSINFO entries the kernel gave us (ppc cache
128 line size). It's a bit nasty in the sense that there's no obvious
129 way to stop uses of some of this info before it's ready to go.
131 Current dependencies are:
133 x86: initially: call VG_(machine_get_hwcaps)
135 then safe to use VG_(machine_get_VexArchInfo)
136 and VG_(machine_x86_have_mxcsr)
138 amd64: initially: call VG_(machine_get_hwcaps)
140 then safe to use VG_(machine_get_VexArchInfo)
142 ppc32: initially: call VG_(machine_get_hwcaps)
143 call VG_(machine_ppc32_set_clszB)
145 then safe to use VG_(machine_get_VexArchInfo)
146 and VG_(machine_ppc32_has_FP)
147 and VG_(machine_ppc32_has_VMX)
149 ppc64: initially: call VG_(machine_get_hwcaps)
150 call VG_(machine_ppc64_set_clszB)
152 then safe to use VG_(machine_get_VexArchInfo)
153 and VG_(machine_ppc64_has_VMX)
155 VG_(machine_get_hwcaps) may use signals (although it attempts to
156 leave signal state unchanged) and therefore should only be
157 called before m_main sets up the client's signal state.
160 /* Determine what insn set and insn set variant the host has, and
161 record it. To be called once at system startup. Returns False if
162 this a CPU incapable of running Valgrind. */
163 extern Bool VG_(machine_get_hwcaps)( void );
165 /* Fetch host cpu info, as per above comment. */
166 extern void VG_(machine_get_VexArchInfo)( /*OUT*/VexArch*,
167 /*OUT*/VexArchInfo* );
169 /* Notify host cpu cache line size, as per above comment. */
170 #if defined(VGA_ppc32)
171 extern void VG_(machine_ppc32_set_clszB)( Int );
174 #if defined(VGA_ppc64)
175 extern void VG_(machine_ppc64_set_clszB)( Int );
178 /* X86: set to 1 if the host is able to do {ld,st}mxcsr (load/store
179 the SSE control/status register), else zero. Is referenced from
180 assembly code, so do not change from a 32-bit int. */
182 extern UInt VG_(machine_x86_have_mxcsr);
185 /* PPC32: set to 1 if FP instructions are supported in user-space,
186 else 0. Is referenced from assembly code, so do not change from a
188 #if defined(VGA_ppc32)
189 extern UInt VG_(machine_ppc32_has_FP);
192 /* PPC32: set to 1 if Altivec instructions are supported in
193 user-space, else 0. Is referenced from assembly code, so do not
194 change from a 32-bit int. */
195 #if defined(VGA_ppc32)
196 extern UInt VG_(machine_ppc32_has_VMX);
199 /* PPC64: set to 1 if Altivec instructions are supported in
200 user-space, else 0. Is referenced from assembly code, so do not
201 change from a 64-bit int. */
202 #if defined(VGA_ppc64)
203 extern ULong VG_(machine_ppc64_has_VMX);
206 #endif // __PUB_CORE_MACHINE_H
208 /*--------------------------------------------------------------------*/
210 /*--------------------------------------------------------------------*/