Search
lxdream.org :: lxdream/src/sh4/xltcache.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/xltcache.h
changeset 561:533f6b478071
prev422:61a0598e07ff
next569:a1c49e1e8776
author nkeynes
date Tue Jan 01 05:08:38 2008 +0000 (16 years ago)
branchlxdream-mmu
permissions -rw-r--r--
last change Enable Id keyword on all source files
file annotate diff log raw
nkeynes@359
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@359
     3
 * 
nkeynes@359
     4
 * Translation cache support (architecture independent)
nkeynes@359
     5
 *
nkeynes@359
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@359
     7
 *
nkeynes@359
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@359
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@359
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@359
    11
 * (at your option) any later version.
nkeynes@359
    12
 *
nkeynes@359
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@359
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@359
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@359
    16
 * GNU General Public License for more details.
nkeynes@359
    17
 */
nkeynes@359
    18
nkeynes@359
    19
#include "dream.h"
nkeynes@359
    20
#include "mem.h"
nkeynes@359
    21
nkeynes@359
    22
typedef struct xlat_cache_block {
nkeynes@359
    23
    int active;  /* 0 = deleted, 1 = normal. 2 = accessed (temp-space only) */
nkeynes@359
    24
    uint32_t size;
nkeynes@359
    25
    void **lut_entry; /* For deletion */
nkeynes@359
    26
    unsigned char code[0];
nkeynes@359
    27
} *xlat_cache_block_t;
nkeynes@359
    28
nkeynes@359
    29
/**
nkeynes@422
    30
 * Initialize the translation cache
nkeynes@422
    31
 */
nkeynes@422
    32
void xlat_cache_init(void);
nkeynes@422
    33
nkeynes@422
    34
/**
nkeynes@359
    35
 * Returns the next block in the new cache list that can be written to by the
nkeynes@359
    36
 * translator.
nkeynes@359
    37
 */
nkeynes@359
    38
xlat_cache_block_t xlat_start_block(sh4addr_t address);
nkeynes@359
    39
nkeynes@359
    40
/**
nkeynes@359
    41
 * Increases the current block size (only valid between calls to xlat_start_block()
nkeynes@359
    42
 * and xlat_commit_block()). 
nkeynes@359
    43
 * @return the new block, which may be different from the old block.
nkeynes@359
    44
 */
nkeynes@410
    45
xlat_cache_block_t xlat_extend_block( uint32_t newSize );
nkeynes@359
    46
nkeynes@359
    47
/**
nkeynes@359
    48
 * Commit the current translation block
nkeynes@359
    49
 * @param addr target address (for the lookup table)
nkeynes@359
    50
 * @param destsize final size of the translation in bytes.
nkeynes@359
    51
 * @param srcsize size of the original data that was translated in bytes
nkeynes@359
    52
 */
nkeynes@359
    53
void xlat_commit_block( uint32_t destsize, uint32_t srcsize );
nkeynes@359
    54
nkeynes@359
    55
/**
nkeynes@376
    56
 * Dump the disassembly of the specified code block to a stream
nkeynes@376
    57
 * (primarily for debugging purposes)
nkeynes@376
    58
 * @param out The stream to write the output to
nkeynes@376
    59
 * @param code a translated block
nkeynes@376
    60
 */
nkeynes@376
    61
void xlat_disasm_block( FILE *out, void *code );
nkeynes@376
    62
nkeynes@376
    63
nkeynes@376
    64
/**
nkeynes@359
    65
 * Delete (deactivate) the specified block from the cache. Caller is responsible
nkeynes@359
    66
 * for ensuring that there really is a block there.
nkeynes@359
    67
 */
nkeynes@359
    68
void xlat_delete_block( xlat_cache_block_t block );
nkeynes@359
    69
nkeynes@359
    70
/**
nkeynes@359
    71
 * Retrieve the entry point for the translated code corresponding to the given
nkeynes@359
    72
 * SH4 address, or NULL if there is no code for that address.
nkeynes@359
    73
 */
nkeynes@359
    74
void *xlat_get_code( sh4addr_t address );
nkeynes@359
    75
nkeynes@359
    76
/**
nkeynes@407
    77
 * Retrieve the address of the lookup table entry corresponding to the
nkeynes@407
    78
 * given SH4 address.
nkeynes@407
    79
 */
nkeynes@407
    80
void **xlat_get_lut_entry( sh4addr_t address );
nkeynes@407
    81
nkeynes@407
    82
/**
nkeynes@366
    83
 * Retrieve the size of the code block starting at the specified pointer. If the
nkeynes@366
    84
 * pointer is not a valid code block, the return value is undefined.
nkeynes@366
    85
 */
nkeynes@366
    86
uint32_t xlat_get_block_size( void *ptr );
nkeynes@366
    87
nkeynes@366
    88
/**
nkeynes@359
    89
 * Flush the code cache for the page containing the given address
nkeynes@359
    90
 */
nkeynes@359
    91
void xlat_flush_page( sh4addr_t address );
nkeynes@359
    92
nkeynes@400
    93
void xlat_invalidate_word( sh4addr_t address );
nkeynes@400
    94
void xlat_invalidate_long( sh4addr_t address );
nkeynes@400
    95
nkeynes@400
    96
nkeynes@400
    97
/**
nkeynes@400
    98
 * Invalidate the code cache for a memory region
nkeynes@400
    99
 */
nkeynes@400
   100
void xlat_invalidate_block( sh4addr_t address, size_t bytes );
nkeynes@400
   101
nkeynes@359
   102
/**
nkeynes@359
   103
 * Flush the entire code cache. This isn't as cheap as one might like
nkeynes@359
   104
 */
nkeynes@359
   105
void xlat_flush_cache();
nkeynes@359
   106
nkeynes@359
   107
/**
nkeynes@359
   108
 * Check the internal integrity of the cache
nkeynes@359
   109
 */
nkeynes@359
   110
void xlat_check_integrity();
.