Search
lxdream.org :: lxdream/src/xlat/xltcache.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/xlat/xltcache.h
changeset 1006:3a169c224c12
prev991:60c7fab9c880
author nkeynes
date Tue Apr 07 10:55:03 2009 +0000 (13 years ago)
branchxlat-refactor
permissions -rw-r--r--
last change Commit current work-in-progress to xlat-refactor branch
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  * Exception table record - this is filled out by the codegen used by the codegen (to backpatch)
    27  * and linker (for longjmp recover)
    28  */;
    29 typedef struct xlat_exception_record {
    30     uint32_t xlat_pc_offset;  // Native PC exception source (relative to start of code block)
    31     uint32_t xlat_exc_offset; // Exception entry point (relative to start of code block)
    32 } *xlat_exception_record_t;
    34 typedef struct xlat_exception_table {
    35     xlat_exception_record_t exc;
    36     size_t next_record;
    37     size_t table_size;
    38 } *xlat_exception_table_t;
    40 /**
    41  * For now, recovery is purely a matter of mapping native pc => sh4 pc,
    42  * and updating sh4r.pc & sh4r.slice_cycles accordingly. In future more
    43  * detailed recovery may be required if the translator optimizes more
    44  * agressively.
    45  *
    46  * The recovery table contains (at least) one entry per abortable instruction,
    47  * 
    48  */
    49 typedef struct xlat_recovery_record {
    50     uint32_t xlat_offset;    // native (translated) pc 
    51     uint32_t sh4_icount;     // instruction number of the corresponding SH4 instruction
    52                              // (0 = first instruction, 1 = second instruction, ... )
    53 } *xlat_recovery_record_t;
    55 struct xlat_cache_block {
    56     int active;  /* 0 = deleted, 1 = normal. 2 = accessed (temp-space only) */
    57     uint32_t size;
    58     void **lut_entry; /* For deletion */
    59     uint32_t xlat_sh4_mode; /* comparison with sh4r.xlat_sh4_mode */
    60     uint32_t recover_table_offset; // Offset from code[0] of the recovery table;
    61     uint32_t recover_table_size;
    62     unsigned char code[0];
    63 } __attribute__((packed));
    65 typedef struct xlat_cache_block *xlat_cache_block_t;
    67 #define XLAT_BLOCK_FOR_CODE(code) (((xlat_cache_block_t)code)-1)
    69 #define XLAT_BLOCK_MODE(code) (XLAT_BLOCK_FOR_CODE(code)->xlat_sh4_mode) 
    71 /**
    72  * Initialize the translation cache
    73  */
    74 void xlat_cache_init(void);
    76 /**
    77  * Returns the next block in the new cache list that can be written to by the
    78  * translator.
    79  */
    80 xlat_cache_block_t xlat_start_block(sh4addr_t address);
    82 /**
    83  * Increases the current block size (only valid between calls to xlat_start_block()
    84  * and xlat_commit_block()). 
    85  * @return the new block, which may be different from the old block.
    86  */
    87 xlat_cache_block_t xlat_extend_block( uint32_t newSize );
    89 /**
    90  * Commit the current translation block
    91  * @param addr target address (for the lookup table)
    92  * @param destsize final size of the translation in bytes.
    93  * @param srcsize size of the original data that was translated in bytes
    94  */
    95 void xlat_commit_block( uint32_t destsize, uint32_t srcsize );
    97 /**
    98  * Dump the disassembly of the specified code block to a stream
    99  * (primarily for debugging purposes)
   100  * @param out The stream to write the output to
   101  * @param code a translated block
   102  */
   103 void xlat_disasm_block( FILE *out, void *code );
   106 /**
   107  * Delete (deactivate) the specified block from the cache. Caller is responsible
   108  * for ensuring that there really is a block there.
   109  */
   110 void xlat_delete_block( xlat_cache_block_t block );
   112 /**
   113  * Retrieve the entry point for the translated code corresponding to the given
   114  * SH4 address, or NULL if there is no code for that address.
   115  */
   116 void * FASTCALL xlat_get_code( sh4addr_t address );
   118 /**
   119  * Retrieve the pre-instruction recovery record corresponding to the given
   120  * native address, or NULL if there is no recovery code for the address.
   121  * @param code The code block containing the recovery table.
   122  * @param native_pc A pointer that must be within the currently executing 
   123  * return the first record before or equal to the given pc.
   124  * translation block.
   125  */
   126 struct xlat_recovery_record *xlat_get_pre_recovery( void *code, void *native_pc );
   129 /**
   130  * Retrieve the entry point for the translated code corresponding to the given
   131  * SH4 virtual address, or NULL if there is no code for the address. 
   132  * If the virtual address cannot be resolved, this method will raise a TLB miss 
   133  * exception, and return NULL.
   134  */
   135 void * FASTCALL xlat_get_code_by_vma( sh4vma_t address );
   137 /**
   138  * Retrieve the address of the lookup table entry corresponding to the
   139  * given SH4 address.
   140  */
   141 void ** FASTCALL xlat_get_lut_entry( sh4addr_t address );
   143 /**
   144  * Retrieve the current host address of the running translated code block.
   145  * @return the host PC, or null if there is no currently executing translated
   146  * block (or the stack is corrupted)
   147  * Note: the implementation of this method is host (and calling-convention) specific.
   148  * @param block_start start of the block the PC should be in
   149  * @param block_size size of the code block in bytes.
   150  */
   151 void *xlat_get_native_pc( void *block_start, uint32_t block_size );
   153 /**
   154  * Retrieve the size of the block starting at the specified pointer. If the
   155  * pointer is not a valid code block, the return value is undefined.
   156  */
   157 uint32_t FASTCALL xlat_get_block_size( void *ptr );
   159 /**
   160  * Retrieve the size of the code in the block starting at the specified 
   161  * pointer. Effectively this is xlat_get_block_size() minus the size of
   162  * the recovery table. If the pointer is not a valid code block, the 
   163  * return value is undefined.
   164  */
   165 uint32_t FASTCALL xlat_get_code_size( void *ptr );
   167 /**
   168  * Flush the code cache for the page containing the given address
   169  */
   170 void FASTCALL xlat_flush_page( sh4addr_t address );
   172 void FASTCALL xlat_invalidate_word( sh4addr_t address );
   173 void FASTCALL xlat_invalidate_long( sh4addr_t address );
   176 /**
   177  * Invalidate the code cache for a memory region
   178  */
   179 void FASTCALL xlat_invalidate_block( sh4addr_t address, size_t bytes );
   181 /**
   182  * Flush the entire code cache. This isn't as cheap as one might like
   183  */
   184 void xlat_flush_cache();
   186 /**
   187  * Check the internal integrity of the cache
   188  */
   189 void xlat_check_integrity();
   191 #endif /* lxdream_xltcache_H */
.