filename | src/xlat/xltcache.h |
changeset | 1091:186558374345 |
prev | 991:60c7fab9c880 |
next | 1149:da6124fceec6 |
author | nkeynes |
date | Fri Sep 10 08:50:55 2010 +1000 (13 years ago) |
permissions | -rw-r--r-- |
last change | Add missing sh4_translate_breakpoint_hit to the symbol table Change asm() to __asm__() as it's more likely to work |
view | annotate | diff | log | raw |
1 /**
2 * $Id$
3 *
4 * Translation cache support (architecture independent)
5 *
6 * Copyright (c) 2005 Nathan Keynes.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */
19 #include "dream.h"
20 #include "mem.h"
22 #ifndef lxdream_xltcache_H
23 #define lxdream_xltcache_H 1
25 /**
26 * For now, recovery is purely a matter of mapping native pc => sh4 pc,
27 * and updating sh4r.pc & sh4r.slice_cycles accordingly. In future more
28 * detailed recovery may be required if the translator optimizes more
29 * agressively.
30 *
31 * The recovery table contains (at least) one entry per abortable instruction,
32 *
33 */
34 typedef struct xlat_recovery_record {
35 uint32_t xlat_offset; // native (translated) pc
36 uint32_t sh4_icount; // instruction number of the corresponding SH4 instruction
37 // (0 = first instruction, 1 = second instruction, ... )
38 } *xlat_recovery_record_t;
40 struct xlat_cache_block {
41 int active; /* 0 = deleted, 1 = normal. 2 = accessed (temp-space only) */
42 uint32_t size;
43 void **lut_entry; /* For deletion */
44 uint32_t xlat_sh4_mode; /* comparison with sh4r.xlat_sh4_mode */
45 uint32_t recover_table_offset; // Offset from code[0] of the recovery table;
46 uint32_t recover_table_size;
47 unsigned char code[0];
48 } __attribute__((packed));
50 typedef struct xlat_cache_block *xlat_cache_block_t;
52 #define XLAT_BLOCK_FOR_CODE(code) (((xlat_cache_block_t)code)-1)
54 #define XLAT_BLOCK_MODE(code) (XLAT_BLOCK_FOR_CODE(code)->xlat_sh4_mode)
55 #define XLAT_RECOVERY_TABLE(code) ((xlat_recovery_record_t)(((char *)code) + XLAT_BLOCK_FOR_CODE(code)->recover_table_offset))
57 /**
58 * Initialize the translation cache
59 */
60 void xlat_cache_init(void);
62 /**
63 * Returns the next block in the new cache list that can be written to by the
64 * translator.
65 */
66 xlat_cache_block_t xlat_start_block(sh4addr_t address);
68 /**
69 * Increases the current block size (only valid between calls to xlat_start_block()
70 * and xlat_commit_block()).
71 * @return the new block, which may be different from the old block.
72 */
73 xlat_cache_block_t xlat_extend_block( uint32_t newSize );
75 /**
76 * Commit the current translation block
77 * @param addr target address (for the lookup table)
78 * @param destsize final size of the translation in bytes.
79 * @param srcsize size of the original data that was translated in bytes
80 */
81 void xlat_commit_block( uint32_t destsize, uint32_t srcsize );
83 /**
84 * Dump the disassembly of the specified code block to a stream
85 * (primarily for debugging purposes)
86 * @param out The stream to write the output to
87 * @param code a translated block
88 */
89 void xlat_disasm_block( FILE *out, void *code );
92 /**
93 * Delete (deactivate) the specified block from the cache. Caller is responsible
94 * for ensuring that there really is a block there.
95 */
96 void xlat_delete_block( xlat_cache_block_t block );
98 /**
99 * Retrieve the entry point for the translated code corresponding to the given
100 * SH4 address, or NULL if there is no code for that address.
101 */
102 void * FASTCALL xlat_get_code( sh4addr_t address );
104 /**
105 * Retrieve the pre-instruction recovery record corresponding to the given
106 * native address, or NULL if there is no recovery code for the address.
107 * @param code The code block containing the recovery table.
108 * @param native_pc A pointer that must be within the currently executing
109 * return the first record before or equal to the given pc.
110 * translation block.
111 */
112 struct xlat_recovery_record *xlat_get_pre_recovery( void *code, void *native_pc );
115 /**
116 * Retrieve the entry point for the translated code corresponding to the given
117 * SH4 virtual address, or NULL if there is no code for the address.
118 * If the virtual address cannot be resolved, this method will raise a TLB miss
119 * exception, and return NULL.
120 */
121 void * FASTCALL xlat_get_code_by_vma( sh4vma_t address );
123 /**
124 * Retrieve the address of the lookup table entry corresponding to the
125 * given SH4 address.
126 */
127 void ** FASTCALL xlat_get_lut_entry( sh4addr_t address );
129 /**
130 * Retrieve the current host address of the running translated code block.
131 * @return the host PC, or null if there is no currently executing translated
132 * block (or the stack is corrupted)
133 * Note: the implementation of this method is host (and calling-convention) specific.
134 * @param block_start start of the block the PC should be in
135 * @param block_size size of the code block in bytes.
136 */
137 void *xlat_get_native_pc( void *block_start, uint32_t block_size );
139 /**
140 * Retrieve the size of the block starting at the specified pointer. If the
141 * pointer is not a valid code block, the return value is undefined.
142 */
143 uint32_t FASTCALL xlat_get_block_size( void *ptr );
145 /**
146 * Retrieve the size of the code in the block starting at the specified
147 * pointer. Effectively this is xlat_get_block_size() minus the size of
148 * the recovery table. If the pointer is not a valid code block, the
149 * return value is undefined.
150 */
151 uint32_t FASTCALL xlat_get_code_size( void *ptr );
153 /**
154 * Flush the code cache for the page containing the given address
155 */
156 void FASTCALL xlat_flush_page( sh4addr_t address );
158 void FASTCALL xlat_invalidate_word( sh4addr_t address );
159 void FASTCALL xlat_invalidate_long( sh4addr_t address );
162 /**
163 * Invalidate the code cache for a memory region
164 */
165 void FASTCALL xlat_invalidate_block( sh4addr_t address, size_t bytes );
167 /**
168 * Flush the entire code cache. This isn't as cheap as one might like
169 */
170 void xlat_flush_cache();
172 /**
173 * Test if the given pointer is within the translation cache, and (is likely)
174 * the start of a code block
175 */
176 gboolean xlat_is_code_pointer( void *p );
178 /**
179 * Check the internal integrity of the cache
180 */
181 void xlat_check_integrity();
183 #endif /* lxdream_xltcache_H */
.