blob: e9f3bc26efd42207d6497599cb0ad255f3d76452 [file] [log] [blame]
njn8bddf582005-05-13 23:40:55 +00001
2/*--------------------------------------------------------------------*/
3/*--- The translation table and cache. ---*/
4/*--- pub_core_transtab.h ---*/
5/*--------------------------------------------------------------------*/
6
7/*
8 This file is part of Valgrind, a dynamic binary instrumentation
9 framework.
10
sewardjb3a1e4b2015-08-21 11:32:26 +000011 Copyright (C) 2000-2015 Julian Seward
njn8bddf582005-05-13 23:40:55 +000012 jseward@acm.org
13
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of the
17 License, or (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 02111-1307, USA.
28
29 The GNU General Public License is contained in the file COPYING.
30*/
31
32#ifndef __PUB_CORE_TRANSTAB_H
33#define __PUB_CORE_TRANSTAB_H
34
35//--------------------------------------------------------------------
36// PURPOSE: This module is responsible for caching translations, and
37// enabling fast look-ups of them.
38//--------------------------------------------------------------------
39
njn2e8f4ef2005-05-14 21:44:20 +000040#include "pub_core_transtab_asm.h"
florian5f1aeb62015-01-13 17:33:59 +000041#include "pub_tool_transtab.h"
floriande6ffbd2014-10-06 16:41:14 +000042#include "libvex.h" // VexGuestExtents
njn2e8f4ef2005-05-14 21:44:20 +000043
sewardj291849f2012-04-20 23:58:55 +000044/* The fast-cache for tt-lookup. Unused entries are denoted by .guest
45 == 1, which is assumed to be a bogus address for all guest code. */
sewardj5f76de02007-02-11 05:08:06 +000046typedef
47 struct {
48 Addr guest;
49 Addr host;
50 }
51 FastCacheEntry;
52
53extern __attribute__((aligned(16)))
54 FastCacheEntry VG_(tt_fast) [VG_TT_FAST_SIZE];
55
56#define TRANSTAB_BOGUS_GUEST_ADDR ((Addr)1)
57
philippe8e1bee42013-10-18 00:08:20 +000058
philippe924c8522015-03-15 12:24:19 +000059/* Initialises the TC, using VG_(clo_num_transtab_sectors)
60 and VG_(clo_avg_transtab_entry_size).
philippe8e1bee42013-10-18 00:08:20 +000061 VG_(clo_num_transtab_sectors) must be >= MIN_N_SECTORS
62 and <= MAX_N_SECTORS. */
njn8bddf582005-05-13 23:40:55 +000063extern void VG_(init_tt_tc) ( void );
64
philippe8e1bee42013-10-18 00:08:20 +000065
66/* Limits for number of sectors the TC is divided into. If you need a larger
67 overall translation cache, increase MAX_N_SECTORS. */
68#define MIN_N_SECTORS 2
sewardja11ec172013-10-18 11:18:45 +000069#define MAX_N_SECTORS 24
philippe8e1bee42013-10-18 00:08:20 +000070
71/* Default for the nr of sectors, if not overriden by command line.
72 On Android, space is limited, so try to get by with fewer sectors.
73 On other platforms we can go to town. 16 sectors gives theoretical
74 capacity of about 440MB of JITted code in 1.05 million translations
75 (realistically, about 2/3 of that) for Memcheck. */
sewardj26ed4192014-11-04 17:44:21 +000076#if defined(VGPV_arm_linux_android) \
77 || defined(VGPV_x86_linux_android) \
78 || defined(VGPV_mips32_linux_android) \
79 || defined(VGPV_arm64_linux_android)
philippe8e1bee42013-10-18 00:08:20 +000080# define N_SECTORS_DEFAULT 6
81#else
82# define N_SECTORS_DEFAULT 16
83#endif
84
njn8bddf582005-05-13 23:40:55 +000085extern
florian518850b2014-10-22 22:25:30 +000086void VG_(add_to_transtab)( const VexGuestExtents* vge,
florianddd61ff2015-01-04 17:20:45 +000087 Addr entry,
florian44bd4462014-12-29 17:04:46 +000088 Addr code,
sewardj26412bd2005-07-07 10:05:05 +000089 UInt code_len,
sewardj291849f2012-04-20 23:58:55 +000090 Bool is_self_checking,
91 Int offs_profInc,
sewardj59731422014-07-24 12:45:24 +000092 UInt n_guest_instrs );
njn8bddf582005-05-13 23:40:55 +000093
philippe523b5b82015-03-23 21:49:32 +000094typedef UShort SECno; // SECno type identifies a sector
95typedef UShort TTEno; // TTEno type identifies a TT entry in a sector.
96
97// 2 constants that indicates Invalid entries.
98#define INV_SNO ((SECno)0xFFFF)
99#define INV_TTE ((TTEno)0xFFFF)
100
sewardj291849f2012-04-20 23:58:55 +0000101extern
102void VG_(tt_tc_do_chaining) ( void* from__patch_addr,
philippe523b5b82015-03-23 21:49:32 +0000103 SECno to_sNo,
104 TTEno to_tteNo,
sewardj291849f2012-04-20 23:58:55 +0000105 Bool to_fastEP );
106
florian44bd4462014-12-29 17:04:46 +0000107extern Bool VG_(search_transtab) ( /*OUT*/Addr* res_hcode,
philippe523b5b82015-03-23 21:49:32 +0000108 /*OUT*/SECno* res_sNo,
109 /*OUT*/TTEno* res_tteNo,
florianddd61ff2015-01-04 17:20:45 +0000110 Addr guest_addr,
njn8bddf582005-05-13 23:40:55 +0000111 Bool upd_cache );
112
florianddd61ff2015-01-04 17:20:45 +0000113extern void VG_(discard_translations) ( Addr start, ULong range,
florian1636d332012-11-15 04:27:04 +0000114 const HChar* who );
njn8bddf582005-05-13 23:40:55 +0000115
njn8bddf582005-05-13 23:40:55 +0000116extern void VG_(print_tt_tc_stats) ( void );
117
118extern UInt VG_(get_bbs_translated) ( void );
119
sewardj0ec07f32006-01-12 12:32:32 +0000120/* Add to / search the auxiliary, small, unredirected translation
121 table. */
122
123extern
florian518850b2014-10-22 22:25:30 +0000124void VG_(add_to_unredir_transtab)( const VexGuestExtents* vge,
florianddd61ff2015-01-04 17:20:45 +0000125 Addr entry,
florian44bd4462014-12-29 17:04:46 +0000126 Addr code,
njn1dcee092009-02-24 03:07:37 +0000127 UInt code_len );
sewardj0ec07f32006-01-12 12:32:32 +0000128extern
florian44bd4462014-12-29 17:04:46 +0000129Bool VG_(search_unredir_transtab) ( /*OUT*/Addr* result,
florianddd61ff2015-01-04 17:20:45 +0000130 Addr guest_addr );
sewardj0ec07f32006-01-12 12:32:32 +0000131
sewardj17c5e2e2012-12-28 09:12:14 +0000132// SB profiling stuff
njn8bddf582005-05-13 23:40:55 +0000133
sewardj17c5e2e2012-12-28 09:12:14 +0000134typedef struct _SBProfEntry {
florianddd61ff2015-01-04 17:20:45 +0000135 Addr addr;
njn2025cf92005-06-26 20:44:48 +0000136 ULong score;
sewardj17c5e2e2012-12-28 09:12:14 +0000137} SBProfEntry;
njn2025cf92005-06-26 20:44:48 +0000138
sewardj17c5e2e2012-12-28 09:12:14 +0000139extern ULong VG_(get_SB_profile) ( SBProfEntry tops[], UInt n_tops );
njn8bddf582005-05-13 23:40:55 +0000140
florian5f1aeb62015-01-13 17:33:59 +0000141// Exported variables
142extern Bool VG_(ok_to_discard_translations);
143
njn8bddf582005-05-13 23:40:55 +0000144#endif // __PUB_CORE_TRANSTAB_H
145
146/*--------------------------------------------------------------------*/
147/*--- end ---*/
148/*--------------------------------------------------------------------*/