Search
lxdream.org :: lxdream/src/xlat/xltcache.h :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/xlat/xltcache.h
changeset 991:60c7fab9c880
next1006:3a169c224c12
next1091:186558374345
author nkeynes
date Wed Mar 04 23:12:21 2009 +0000 (15 years ago)
permissions -rw-r--r--
last change Move xltcache to xlat/ src directory
Commit new and improved x86 opcode file - cleaned up and added support for amd64 extended registers
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/xlat/xltcache.h Wed Mar 04 23:12:21 2009 +0000
1.3 @@ -0,0 +1,176 @@
1.4 +/**
1.5 + * $Id$
1.6 + *
1.7 + * Translation cache support (architecture independent)
1.8 + *
1.9 + * Copyright (c) 2005 Nathan Keynes.
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.15 + *
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.20 + */
1.21 +
1.22 +#include "dream.h"
1.23 +#include "mem.h"
1.24 +
1.25 +#ifndef lxdream_xltcache_H
1.26 +#define lxdream_xltcache_H 1
1.27 +
1.28 +/**
1.29 + * For now, recovery is purely a matter of mapping native pc => sh4 pc,
1.30 + * and updating sh4r.pc & sh4r.slice_cycles accordingly. In future more
1.31 + * detailed recovery may be required if the translator optimizes more
1.32 + * agressively.
1.33 + *
1.34 + * The recovery table contains (at least) one entry per abortable instruction,
1.35 + *
1.36 + */
1.37 +typedef struct xlat_recovery_record {
1.38 + uint32_t xlat_offset; // native (translated) pc
1.39 + uint32_t sh4_icount; // instruction number of the corresponding SH4 instruction
1.40 + // (0 = first instruction, 1 = second instruction, ... )
1.41 +} *xlat_recovery_record_t;
1.42 +
1.43 +struct xlat_cache_block {
1.44 + int active; /* 0 = deleted, 1 = normal. 2 = accessed (temp-space only) */
1.45 + uint32_t size;
1.46 + void **lut_entry; /* For deletion */
1.47 + uint32_t xlat_sh4_mode; /* comparison with sh4r.xlat_sh4_mode */
1.48 + uint32_t recover_table_offset; // Offset from code[0] of the recovery table;
1.49 + uint32_t recover_table_size;
1.50 + unsigned char code[0];
1.51 +} __attribute__((packed));
1.52 +
1.53 +typedef struct xlat_cache_block *xlat_cache_block_t;
1.54 +
1.55 +#define XLAT_BLOCK_FOR_CODE(code) (((xlat_cache_block_t)code)-1)
1.56 +
1.57 +#define XLAT_BLOCK_MODE(code) (XLAT_BLOCK_FOR_CODE(code)->xlat_sh4_mode)
1.58 +
1.59 +/**
1.60 + * Initialize the translation cache
1.61 + */
1.62 +void xlat_cache_init(void);
1.63 +
1.64 +/**
1.65 + * Returns the next block in the new cache list that can be written to by the
1.66 + * translator.
1.67 + */
1.68 +xlat_cache_block_t xlat_start_block(sh4addr_t address);
1.69 +
1.70 +/**
1.71 + * Increases the current block size (only valid between calls to xlat_start_block()
1.72 + * and xlat_commit_block()).
1.73 + * @return the new block, which may be different from the old block.
1.74 + */
1.75 +xlat_cache_block_t xlat_extend_block( uint32_t newSize );
1.76 +
1.77 +/**
1.78 + * Commit the current translation block
1.79 + * @param addr target address (for the lookup table)
1.80 + * @param destsize final size of the translation in bytes.
1.81 + * @param srcsize size of the original data that was translated in bytes
1.82 + */
1.83 +void xlat_commit_block( uint32_t destsize, uint32_t srcsize );
1.84 +
1.85 +/**
1.86 + * Dump the disassembly of the specified code block to a stream
1.87 + * (primarily for debugging purposes)
1.88 + * @param out The stream to write the output to
1.89 + * @param code a translated block
1.90 + */
1.91 +void xlat_disasm_block( FILE *out, void *code );
1.92 +
1.93 +
1.94 +/**
1.95 + * Delete (deactivate) the specified block from the cache. Caller is responsible
1.96 + * for ensuring that there really is a block there.
1.97 + */
1.98 +void xlat_delete_block( xlat_cache_block_t block );
1.99 +
1.100 +/**
1.101 + * Retrieve the entry point for the translated code corresponding to the given
1.102 + * SH4 address, or NULL if there is no code for that address.
1.103 + */
1.104 +void * FASTCALL xlat_get_code( sh4addr_t address );
1.105 +
1.106 +/**
1.107 + * Retrieve the pre-instruction recovery record corresponding to the given
1.108 + * native address, or NULL if there is no recovery code for the address.
1.109 + * @param code The code block containing the recovery table.
1.110 + * @param native_pc A pointer that must be within the currently executing
1.111 + * return the first record before or equal to the given pc.
1.112 + * translation block.
1.113 + */
1.114 +struct xlat_recovery_record *xlat_get_pre_recovery( void *code, void *native_pc );
1.115 +
1.116 +
1.117 +/**
1.118 + * Retrieve the entry point for the translated code corresponding to the given
1.119 + * SH4 virtual address, or NULL if there is no code for the address.
1.120 + * If the virtual address cannot be resolved, this method will raise a TLB miss
1.121 + * exception, and return NULL.
1.122 + */
1.123 +void * FASTCALL xlat_get_code_by_vma( sh4vma_t address );
1.124 +
1.125 +/**
1.126 + * Retrieve the address of the lookup table entry corresponding to the
1.127 + * given SH4 address.
1.128 + */
1.129 +void ** FASTCALL xlat_get_lut_entry( sh4addr_t address );
1.130 +
1.131 +/**
1.132 + * Retrieve the current host address of the running translated code block.
1.133 + * @return the host PC, or null if there is no currently executing translated
1.134 + * block (or the stack is corrupted)
1.135 + * Note: the implementation of this method is host (and calling-convention) specific.
1.136 + * @param block_start start of the block the PC should be in
1.137 + * @param block_size size of the code block in bytes.
1.138 + */
1.139 +void *xlat_get_native_pc( void *block_start, uint32_t block_size );
1.140 +
1.141 +/**
1.142 + * Retrieve the size of the block starting at the specified pointer. If the
1.143 + * pointer is not a valid code block, the return value is undefined.
1.144 + */
1.145 +uint32_t FASTCALL xlat_get_block_size( void *ptr );
1.146 +
1.147 +/**
1.148 + * Retrieve the size of the code in the block starting at the specified
1.149 + * pointer. Effectively this is xlat_get_block_size() minus the size of
1.150 + * the recovery table. If the pointer is not a valid code block, the
1.151 + * return value is undefined.
1.152 + */
1.153 +uint32_t FASTCALL xlat_get_code_size( void *ptr );
1.154 +
1.155 +/**
1.156 + * Flush the code cache for the page containing the given address
1.157 + */
1.158 +void FASTCALL xlat_flush_page( sh4addr_t address );
1.159 +
1.160 +void FASTCALL xlat_invalidate_word( sh4addr_t address );
1.161 +void FASTCALL xlat_invalidate_long( sh4addr_t address );
1.162 +
1.163 +
1.164 +/**
1.165 + * Invalidate the code cache for a memory region
1.166 + */
1.167 +void FASTCALL xlat_invalidate_block( sh4addr_t address, size_t bytes );
1.168 +
1.169 +/**
1.170 + * Flush the entire code cache. This isn't as cheap as one might like
1.171 + */
1.172 +void xlat_flush_cache();
1.173 +
1.174 +/**
1.175 + * Check the internal integrity of the cache
1.176 + */
1.177 +void xlat_check_integrity();
1.178 +
1.179 +#endif /* lxdream_xltcache_H */
.