njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 1 | |
| 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 | |
sewardj | 0f157dd | 2013-10-18 14:27:36 +0000 | [diff] [blame] | 11 | Copyright (C) 2000-2013 Julian Seward |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 12 | 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 | |
njn | 2e8f4ef | 2005-05-14 21:44:20 +0000 | [diff] [blame] | 40 | #include "pub_core_transtab_asm.h" |
| 41 | |
sewardj | 291849f | 2012-04-20 23:58:55 +0000 | [diff] [blame] | 42 | /* The fast-cache for tt-lookup. Unused entries are denoted by .guest |
| 43 | == 1, which is assumed to be a bogus address for all guest code. */ |
sewardj | 5f76de0 | 2007-02-11 05:08:06 +0000 | [diff] [blame] | 44 | typedef |
| 45 | struct { |
| 46 | Addr guest; |
| 47 | Addr host; |
| 48 | } |
| 49 | FastCacheEntry; |
| 50 | |
| 51 | extern __attribute__((aligned(16))) |
| 52 | FastCacheEntry VG_(tt_fast) [VG_TT_FAST_SIZE]; |
| 53 | |
| 54 | #define TRANSTAB_BOGUS_GUEST_ADDR ((Addr)1) |
| 55 | |
philippe | 8e1bee4 | 2013-10-18 00:08:20 +0000 | [diff] [blame] | 56 | |
| 57 | /* Initialises the TC, using VG_(clo_num_transtab_sectors). |
| 58 | VG_(clo_num_transtab_sectors) must be >= MIN_N_SECTORS |
| 59 | and <= MAX_N_SECTORS. */ |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 60 | extern void VG_(init_tt_tc) ( void ); |
| 61 | |
philippe | 8e1bee4 | 2013-10-18 00:08:20 +0000 | [diff] [blame] | 62 | |
| 63 | /* Limits for number of sectors the TC is divided into. If you need a larger |
| 64 | overall translation cache, increase MAX_N_SECTORS. */ |
| 65 | #define MIN_N_SECTORS 2 |
sewardj | a11ec17 | 2013-10-18 11:18:45 +0000 | [diff] [blame] | 66 | #define MAX_N_SECTORS 24 |
philippe | 8e1bee4 | 2013-10-18 00:08:20 +0000 | [diff] [blame] | 67 | |
| 68 | /* Default for the nr of sectors, if not overriden by command line. |
| 69 | On Android, space is limited, so try to get by with fewer sectors. |
| 70 | On other platforms we can go to town. 16 sectors gives theoretical |
| 71 | capacity of about 440MB of JITted code in 1.05 million translations |
| 72 | (realistically, about 2/3 of that) for Memcheck. */ |
| 73 | #if defined(VGPV_arm_linux_android) || defined(VGPV_x86_linux_android) |
| 74 | # define N_SECTORS_DEFAULT 6 |
| 75 | #else |
| 76 | # define N_SECTORS_DEFAULT 16 |
| 77 | #endif |
| 78 | |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 79 | extern |
| 80 | void VG_(add_to_transtab)( VexGuestExtents* vge, |
| 81 | Addr64 entry, |
| 82 | AddrH code, |
sewardj | 26412bd | 2005-07-07 10:05:05 +0000 | [diff] [blame] | 83 | UInt code_len, |
sewardj | 291849f | 2012-04-20 23:58:55 +0000 | [diff] [blame] | 84 | Bool is_self_checking, |
| 85 | Int offs_profInc, |
sewardj | b7301c6 | 2012-04-24 11:50:49 +0000 | [diff] [blame] | 86 | UInt n_guest_instrs, |
sewardj | 291849f | 2012-04-20 23:58:55 +0000 | [diff] [blame] | 87 | VexArch arch_host ); |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 88 | |
sewardj | 291849f | 2012-04-20 23:58:55 +0000 | [diff] [blame] | 89 | extern |
| 90 | void VG_(tt_tc_do_chaining) ( void* from__patch_addr, |
| 91 | UInt to_sNo, |
| 92 | UInt to_tteNo, |
| 93 | Bool to_fastEP ); |
| 94 | |
| 95 | extern Bool VG_(search_transtab) ( /*OUT*/AddrH* res_hcode, |
| 96 | /*OUT*/UInt* res_sNo, |
| 97 | /*OUT*/UInt* res_tteNo, |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 98 | Addr64 guest_addr, |
| 99 | Bool upd_cache ); |
| 100 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 101 | extern void VG_(discard_translations) ( Addr64 start, ULong range, |
florian | 1636d33 | 2012-11-15 04:27:04 +0000 | [diff] [blame] | 102 | const HChar* who ); |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 103 | |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 104 | extern void VG_(print_tt_tc_stats) ( void ); |
| 105 | |
| 106 | extern UInt VG_(get_bbs_translated) ( void ); |
| 107 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 108 | /* Add to / search the auxiliary, small, unredirected translation |
| 109 | table. */ |
| 110 | |
| 111 | extern |
| 112 | void VG_(add_to_unredir_transtab)( VexGuestExtents* vge, |
| 113 | Addr64 entry, |
| 114 | AddrH code, |
njn | 1dcee09 | 2009-02-24 03:07:37 +0000 | [diff] [blame] | 115 | UInt code_len ); |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 116 | extern |
| 117 | Bool VG_(search_unredir_transtab) ( /*OUT*/AddrH* result, |
| 118 | Addr64 guest_addr ); |
| 119 | |
sewardj | 17c5e2e | 2012-12-28 09:12:14 +0000 | [diff] [blame] | 120 | // SB profiling stuff |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 121 | |
sewardj | 17c5e2e | 2012-12-28 09:12:14 +0000 | [diff] [blame] | 122 | typedef struct _SBProfEntry { |
njn | 2025cf9 | 2005-06-26 20:44:48 +0000 | [diff] [blame] | 123 | Addr64 addr; |
| 124 | ULong score; |
sewardj | 17c5e2e | 2012-12-28 09:12:14 +0000 | [diff] [blame] | 125 | } SBProfEntry; |
njn | 2025cf9 | 2005-06-26 20:44:48 +0000 | [diff] [blame] | 126 | |
sewardj | 17c5e2e | 2012-12-28 09:12:14 +0000 | [diff] [blame] | 127 | extern ULong VG_(get_SB_profile) ( SBProfEntry tops[], UInt n_tops ); |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 128 | |
| 129 | #endif // __PUB_CORE_TRANSTAB_H |
| 130 | |
| 131 | /*--------------------------------------------------------------------*/ |
| 132 | /*--- end ---*/ |
| 133 | /*--------------------------------------------------------------------*/ |