nkeynes@359: /** nkeynes@586: * $Id$ nkeynes@359: * nkeynes@359: * Translation cache support (architecture independent) nkeynes@359: * nkeynes@359: * Copyright (c) 2005 Nathan Keynes. nkeynes@359: * nkeynes@359: * This program is free software; you can redistribute it and/or modify nkeynes@359: * it under the terms of the GNU General Public License as published by nkeynes@359: * the Free Software Foundation; either version 2 of the License, or nkeynes@359: * (at your option) any later version. nkeynes@359: * nkeynes@359: * This program is distributed in the hope that it will be useful, nkeynes@359: * but WITHOUT ANY WARRANTY; without even the implied warranty of nkeynes@359: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the nkeynes@359: * GNU General Public License for more details. nkeynes@359: */ nkeynes@359: nkeynes@359: #include "dream.h" nkeynes@359: #include "mem.h" nkeynes@359: nkeynes@586: #ifndef lxdream_xltcache_H nkeynes@586: #define lxdream_xltcache_H nkeynes@586: nkeynes@586: /** nkeynes@586: * For now, recovery is purely a matter of mapping native pc => sh4 pc, nkeynes@586: * and updating sh4r.pc & sh4r.slice_cycles accordingly. In future more nkeynes@586: * detailed recovery may be required if the translator optimizes more nkeynes@586: * agressively. nkeynes@586: * nkeynes@586: * The recovery table contains (at least) one entry per abortable instruction, nkeynes@586: * nkeynes@586: */ nkeynes@586: typedef struct xlat_recovery_record { nkeynes@596: uint32_t xlat_offset; // native (translated) pc nkeynes@586: uint32_t sh4_icount; // instruction number of the corresponding SH4 instruction nkeynes@586: // (0 = first instruction, 1 = second instruction, ... ) nkeynes@586: } *xlat_recovery_record_t; nkeynes@586: nkeynes@586: struct xlat_cache_block { nkeynes@359: int active; /* 0 = deleted, 1 = normal. 2 = accessed (temp-space only) */ nkeynes@359: uint32_t size; nkeynes@359: void **lut_entry; /* For deletion */ nkeynes@592: uint32_t recover_table_offset; // Offset from code[0] of the recovery table; nkeynes@586: uint32_t recover_table_size; nkeynes@359: unsigned char code[0]; nkeynes@586: } __attribute__((packed)); nkeynes@586: nkeynes@586: typedef struct xlat_cache_block *xlat_cache_block_t; nkeynes@359: nkeynes@359: /** nkeynes@422: * Initialize the translation cache nkeynes@422: */ nkeynes@422: void xlat_cache_init(void); nkeynes@422: nkeynes@422: /** nkeynes@359: * Returns the next block in the new cache list that can be written to by the nkeynes@359: * translator. nkeynes@359: */ nkeynes@359: xlat_cache_block_t xlat_start_block(sh4addr_t address); nkeynes@359: nkeynes@359: /** nkeynes@359: * Increases the current block size (only valid between calls to xlat_start_block() nkeynes@359: * and xlat_commit_block()). nkeynes@359: * @return the new block, which may be different from the old block. nkeynes@359: */ nkeynes@410: xlat_cache_block_t xlat_extend_block( uint32_t newSize ); nkeynes@359: nkeynes@359: /** nkeynes@359: * Commit the current translation block nkeynes@359: * @param addr target address (for the lookup table) nkeynes@359: * @param destsize final size of the translation in bytes. nkeynes@359: * @param srcsize size of the original data that was translated in bytes nkeynes@359: */ nkeynes@359: void xlat_commit_block( uint32_t destsize, uint32_t srcsize ); nkeynes@359: nkeynes@359: /** nkeynes@376: * Dump the disassembly of the specified code block to a stream nkeynes@376: * (primarily for debugging purposes) nkeynes@376: * @param out The stream to write the output to nkeynes@376: * @param code a translated block nkeynes@376: */ nkeynes@376: void xlat_disasm_block( FILE *out, void *code ); nkeynes@376: nkeynes@376: nkeynes@376: /** nkeynes@359: * Delete (deactivate) the specified block from the cache. Caller is responsible nkeynes@359: * for ensuring that there really is a block there. nkeynes@359: */ nkeynes@359: void xlat_delete_block( xlat_cache_block_t block ); nkeynes@359: nkeynes@359: /** nkeynes@359: * Retrieve the entry point for the translated code corresponding to the given nkeynes@359: * SH4 address, or NULL if there is no code for that address. nkeynes@359: */ nkeynes@359: void *xlat_get_code( sh4addr_t address ); nkeynes@359: nkeynes@359: /** nkeynes@586: * Retrieve the recovery record corresponding to the given nkeynes@586: * native address, or NULL if there is no recovery code for the address. nkeynes@586: * @param code The code block containing the recovery table. nkeynes@586: * @param native_pc A pointer that must be within the currently executing nkeynes@586: * @param recover_after If TRUE, return the first record after the given pc, otherwise nkeynes@586: * return the first record before or equal to the given pc. nkeynes@586: * translation block. nkeynes@586: */ nkeynes@586: struct xlat_recovery_record *xlat_get_recovery( void *code, void *native_pc, gboolean recover_after ); nkeynes@586: nkeynes@586: /** nkeynes@586: * Retrieve the entry point for the translated code corresponding to the given nkeynes@586: * SH4 virtual address, or NULL if there is no code for the address. nkeynes@586: * If the virtual address cannot be resolved, this method will raise a TLB miss nkeynes@586: * exception, and return NULL. nkeynes@586: */ nkeynes@586: void *xlat_get_code_by_vma( sh4vma_t address ); nkeynes@586: nkeynes@586: /** nkeynes@407: * Retrieve the address of the lookup table entry corresponding to the nkeynes@407: * given SH4 address. nkeynes@407: */ nkeynes@407: void **xlat_get_lut_entry( sh4addr_t address ); nkeynes@407: nkeynes@407: /** nkeynes@586: * Retrieve the current host address of the running translated code block. nkeynes@586: * @return the host PC, or null if there is no currently executing translated nkeynes@586: * block (or the stack is corrupted) nkeynes@586: * Note: this method is implemented in host-specific asm. nkeynes@586: */ nkeynes@586: void *xlat_get_native_pc(); nkeynes@586: nkeynes@586: /** nkeynes@586: * Retrieve the size of the block starting at the specified pointer. If the nkeynes@366: * pointer is not a valid code block, the return value is undefined. nkeynes@366: */ nkeynes@366: uint32_t xlat_get_block_size( void *ptr ); nkeynes@366: nkeynes@366: /** nkeynes@586: * Retrieve the size of the code in the block starting at the specified nkeynes@586: * pointer. Effectively this is xlat_get_block_size() minus the size of nkeynes@586: * the recovery table. If the pointer is not a valid code block, the nkeynes@586: * return value is undefined. nkeynes@586: */ nkeynes@586: uint32_t xlat_get_code_size( void *ptr ); nkeynes@586: nkeynes@586: /** nkeynes@359: * Flush the code cache for the page containing the given address nkeynes@359: */ nkeynes@359: void xlat_flush_page( sh4addr_t address ); nkeynes@359: nkeynes@400: void xlat_invalidate_word( sh4addr_t address ); nkeynes@400: void xlat_invalidate_long( sh4addr_t address ); nkeynes@400: nkeynes@400: nkeynes@400: /** nkeynes@400: * Invalidate the code cache for a memory region nkeynes@400: */ nkeynes@400: void xlat_invalidate_block( sh4addr_t address, size_t bytes ); nkeynes@400: nkeynes@359: /** nkeynes@359: * Flush the entire code cache. This isn't as cheap as one might like nkeynes@359: */ nkeynes@359: void xlat_flush_cache(); nkeynes@359: nkeynes@359: /** nkeynes@359: * Check the internal integrity of the cache nkeynes@359: */ nkeynes@359: void xlat_check_integrity(); nkeynes@586: nkeynes@586: #endif /* lxdream_xltcache_H */