Search
lxdream.org :: lxdream/src/sh4/xltcache.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/xltcache.h
changeset 571:9bc09948d0f2
prev569:a1c49e1e8776
next580:508dc852a8eb
author nkeynes
date Thu Jan 10 08:28:37 2008 +0000 (14 years ago)
branchlxdream-mmu
permissions -rw-r--r--
last change More MMU work in progess. Much better now...
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
    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     uintptr_t xlat_pc;    // 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 typedef 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     xlat_recovery_record_t recover_table;
    45     uint32_t recover_table_size;
    46     unsigned char code[0];
    47 } *xlat_cache_block_t;
    49 /**
    50  * Initialize the translation cache
    51  */
    52 void xlat_cache_init(void);
    54 /**
    55  * Returns the next block in the new cache list that can be written to by the
    56  * translator.
    57  */
    58 xlat_cache_block_t xlat_start_block(sh4addr_t address);
    60 /**
    61  * Increases the current block size (only valid between calls to xlat_start_block()
    62  * and xlat_commit_block()). 
    63  * @return the new block, which may be different from the old block.
    64  */
    65 xlat_cache_block_t xlat_extend_block( uint32_t newSize );
    67 /**
    68  * Commit the current translation block
    69  * @param addr target address (for the lookup table)
    70  * @param destsize final size of the translation in bytes.
    71  * @param srcsize size of the original data that was translated in bytes
    72  */
    73 void xlat_commit_block( uint32_t destsize, uint32_t srcsize );
    75 /**
    76  * Dump the disassembly of the specified code block to a stream
    77  * (primarily for debugging purposes)
    78  * @param out The stream to write the output to
    79  * @param code a translated block
    80  */
    81 void xlat_disasm_block( FILE *out, void *code );
    84 /**
    85  * Delete (deactivate) the specified block from the cache. Caller is responsible
    86  * for ensuring that there really is a block there.
    87  */
    88 void xlat_delete_block( xlat_cache_block_t block );
    90 /**
    91  * Retrieve the entry point for the translated code corresponding to the given
    92  * SH4 address, or NULL if there is no code for that address.
    93  */
    94 void *xlat_get_code( sh4addr_t address );
    96 /**
    97  * Retrieve the recovery record corresponding to the given
    98  * native address, or NULL if there is no recovery code for the address.
    99  * @param code The code block containing the recovery table.
   100  * @param native_pc A pointer that must be within the currently executing 
   101  * @param recover_after If TRUE, return the first record after the given pc, otherwise
   102  * return the first record before or equal to the given pc.
   103  * translation block.
   104  */
   105 struct xlat_recovery_record *xlat_get_recovery( void *code, void *native_pc, gboolean recover_after );
   107 /**
   108  * Retrieve the entry point for the translated code corresponding to the given
   109  * SH4 virtual address, or NULL if there is no code for the address. 
   110  * If the virtual address cannot be resolved, this method will raise a TLB miss 
   111  * exception, and return NULL.
   112  */
   113 void *xlat_get_code_by_vma( sh4vma_t address );
   115 /**
   116  * Retrieve the address of the lookup table entry corresponding to the
   117  * given SH4 address.
   118  */
   119 void **xlat_get_lut_entry( sh4addr_t address );
   121 /**
   122  * Retrieve the current host address of the running translated code block.
   123  * @return the host PC, or null if there is no currently executing translated
   124  * block (or the stack is corrupted)
   125  * Note: this method is implemented in host-specific asm.
   126  */
   127 void *xlat_get_native_pc();
   129 /**
   130  * Retrieve the size of the block starting at the specified pointer. If the
   131  * pointer is not a valid code block, the return value is undefined.
   132  */
   133 uint32_t xlat_get_block_size( void *ptr );
   135 /**
   136  * Retrieve the size of the code in the block starting at the specified 
   137  * pointer. Effectively this is xlat_get_block_size() minus the size of
   138  * the recovery table. If the pointer is not a valid code block, the 
   139  * return value is undefined.
   140  */
   141 uint32_t xlat_get_code_size( void *ptr );
   143 /**
   144  * Flush the code cache for the page containing the given address
   145  */
   146 void xlat_flush_page( sh4addr_t address );
   148 void xlat_invalidate_word( sh4addr_t address );
   149 void xlat_invalidate_long( sh4addr_t address );
   152 /**
   153  * Invalidate the code cache for a memory region
   154  */
   155 void xlat_invalidate_block( sh4addr_t address, size_t bytes );
   157 /**
   158  * Flush the entire code cache. This isn't as cheap as one might like
   159  */
   160 void xlat_flush_cache();
   162 /**
   163  * Check the internal integrity of the cache
   164  */
   165 void xlat_check_integrity();
   167 #endif /* lxdream_xltcache_H */
.