blob: 6775bc1997617fa4e7cfedc9a1b261a9ca112f14 [file] [log] [blame]
njnf536bbb2005-06-13 04:21:38 +00001
2/*--------------------------------------------------------------------*/
3/*--- Machine-related stuff. pub_tool_machine.h ---*/
4/*--------------------------------------------------------------------*/
5
6/*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
9
sewardj4d474d02008-02-11 11:34:59 +000010 Copyright (C) 2000-2008 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
njn4a164d02005-06-18 18:49:40 +000031#ifndef __PUB_TOOL_MACHINE_H
32#define __PUB_TOOL_MACHINE_H
njnf536bbb2005-06-13 04:21:38 +000033
sewardjf1c91e02006-10-17 01:35:58 +000034#if defined(VGP_x86_linux)
njna5ad9ba2005-11-10 15:20:37 +000035# define VG_MIN_INSTR_SZB 1 // min length of native instruction
36# define VG_MAX_INSTR_SZB 16 // max length of native instruction
sewardj0ec07f32006-01-12 12:32:32 +000037# define VG_CLREQ_SZB 14 // length of a client request, may
njna5ad9ba2005-11-10 15:20:37 +000038 // be larger than VG_MAX_INSTR_SZB
sewardjc2812332005-12-23 23:34:51 +000039# define VG_STACK_REDZONE_SZB 0 // number of addressable bytes below %RSP
sewardjf1c91e02006-10-17 01:35:58 +000040#elif defined(VGP_amd64_linux)
njnaf839f52005-06-23 03:27:57 +000041# define VG_MIN_INSTR_SZB 1
42# define VG_MAX_INSTR_SZB 16
sewardj0ec07f32006-01-12 12:32:32 +000043# define VG_CLREQ_SZB 19
njnaf839f52005-06-23 03:27:57 +000044# define VG_STACK_REDZONE_SZB 128
sewardjf1c91e02006-10-17 01:35:58 +000045#elif defined(VGP_ppc32_linux)
njnaf839f52005-06-23 03:27:57 +000046# define VG_MIN_INSTR_SZB 4
47# define VG_MAX_INSTR_SZB 4
sewardjd68ac3e2006-01-20 14:31:57 +000048# define VG_CLREQ_SZB 20
njnaf839f52005-06-23 03:27:57 +000049# define VG_STACK_REDZONE_SZB 0
sewardjf1c91e02006-10-17 01:35:58 +000050#elif defined(VGP_ppc64_linux)
sewardj2c48c7b2005-11-29 13:05:56 +000051# define VG_MIN_INSTR_SZB 4
52# define VG_MAX_INSTR_SZB 4
sewardjd68ac3e2006-01-20 14:31:57 +000053# define VG_CLREQ_SZB 20
sewardjc2812332005-12-23 23:34:51 +000054# define VG_STACK_REDZONE_SZB 288 // number of addressable bytes below R1
55 // from 64-bit PowerPC ELF ABI Supplement 1.7
sewardjf1c91e02006-10-17 01:35:58 +000056#elif defined(VGP_ppc32_aix5)
57# define VG_MIN_INSTR_SZB 4
58# define VG_MAX_INSTR_SZB 4
59# define VG_CLREQ_SZB 20
60 /* The PowerOpen ABI actually says 220 bytes, but that is not an
61 8-aligned number, and frequently forces Memcheck's
62 mc_{new,die}_mem_stack_N routines into slow cases by losing
63 8-alignment of the area to be messed with. So let's just say
64 224 instead. Gdb has a similar kludge. */
65# define VG_STACK_REDZONE_SZB 224
66#elif defined(VGP_ppc64_aix5)
67# define VG_MIN_INSTR_SZB 4
68# define VG_MAX_INSTR_SZB 4
69# define VG_CLREQ_SZB 20
70# define VG_STACK_REDZONE_SZB 288 // is this right?
njnf536bbb2005-06-13 04:21:38 +000071#else
sewardjf1c91e02006-10-17 01:35:58 +000072# error Unknown platform
njnf536bbb2005-06-13 04:21:38 +000073#endif
74
75// Guest state accessors
76extern Addr VG_(get_SP) ( ThreadId tid );
77extern Addr VG_(get_IP) ( ThreadId tid );
78extern Addr VG_(get_FP) ( ThreadId tid );
sewardjacaec5f2005-08-19 16:02:59 +000079extern Addr VG_(get_LR) ( ThreadId tid );
njnf536bbb2005-06-13 04:21:38 +000080
81extern void VG_(set_SP) ( ThreadId tid, Addr sp );
82extern void VG_(set_IP) ( ThreadId tid, Addr ip );
83
84// For get/set, 'area' is where the asked-for shadow state will be copied
85// into/from.
sewardj7cf4e6b2008-05-01 20:24:26 +000086void
87VG_(get_shadow_regs_area) ( ThreadId tid,
88 /*DST*/UChar* dst,
89 /*SRC*/Int shadowNo, OffT offset, SizeT size );
90void
91VG_(set_shadow_regs_area) ( ThreadId tid,
92 /*DST*/Int shadowNo, OffT offset, SizeT size,
93 /*SRC*/const UChar* src );
njnf536bbb2005-06-13 04:21:38 +000094
njn6ace3ea2005-06-17 03:06:27 +000095// Apply a function 'f' to all the general purpose registers in all the
96// current threads.
97// This is very Memcheck-specific -- it's used to find the roots when
98// doing leak checking.
99extern void VG_(apply_to_GP_regs)(void (*f)(UWord val));
100
sewardjb8b79ad2008-03-03 01:35:41 +0000101// This iterator lets you inspect each live thread's stack bounds.
102// Returns False at the end. 'tid' is the iterator and you can only
103// safely change it by making calls to these functions.
104extern void VG_(thread_stack_reset_iter) ( /*OUT*/ThreadId* tid );
105extern Bool VG_(thread_stack_next) ( /*MOD*/ThreadId* tid,
106 /*OUT*/Addr* stack_min,
107 /*OUT*/Addr* stack_max );
njnb506bd82005-06-21 04:01:51 +0000108
sewardjbbec7722007-11-25 14:08:53 +0000109// Returns .client_stack_highest_word for the given thread
110extern Addr VG_(thread_get_stack_max) ( ThreadId tid );
111
bart0fb03202008-03-29 09:25:53 +0000112// Returns how many bytes have been allocated for the stack of the given thread
113extern Addr VG_(thread_get_stack_size) ( ThreadId tid );
114
sewardj53ee1fc2005-12-23 02:29:58 +0000115// Given a pointer to a function as obtained by "& functionname" in C,
116// produce a pointer to the actual entry point for the function. For
117// most platforms it's the identity function. Unfortunately, on
118// ppc64-linux it isn't (sigh).
119extern void* VG_(fnptr_to_fnentry)( void* );
120
njn4a164d02005-06-18 18:49:40 +0000121#endif // __PUB_TOOL_MACHINE_H
njnf536bbb2005-06-13 04:21:38 +0000122
123/*--------------------------------------------------------------------*/
124/*--- end ---*/
125/*--------------------------------------------------------------------*/