Search
lxdream.org :: lxdream/src/sh4/xltcache.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/xltcache.h
changeset 580:508dc852a8eb
prev571:9bc09948d0f2
author nkeynes
date Tue Jan 15 02:20:30 2008 +0000 (14 years ago)
branchlxdream-mmu
permissions -rw-r--r--
last change Fix x86-64 support for mmu changes
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@571
    22
#ifndef lxdream_xltcache_H
nkeynes@571
    23
#define lxdream_xltcache_H
nkeynes@571
    24
nkeynes@571
    25
/**
nkeynes@571
    26
 * For now, recovery is purely a matter of mapping native pc => sh4 pc,
nkeynes@571
    27
 * and updating sh4r.pc & sh4r.slice_cycles accordingly. In future more
nkeynes@571
    28
 * detailed recovery may be required if the translator optimizes more
nkeynes@571
    29
 * agressively.
nkeynes@571
    30
 *
nkeynes@571
    31
 * The recovery table contains (at least) one entry per abortable instruction,
nkeynes@571
    32
 * 
nkeynes@571
    33
 */
nkeynes@571
    34
typedef struct xlat_recovery_record {
nkeynes@571
    35
    uintptr_t xlat_pc;    // native (translated) pc 
nkeynes@571
    36
    uint32_t sh4_icount; // instruction number of the corresponding SH4 instruction
nkeynes@571
    37
                         // (0 = first instruction, 1 = second instruction, ... )
nkeynes@571
    38
} *xlat_recovery_record_t;
nkeynes@571
    39
nkeynes@580
    40
struct xlat_cache_block {
nkeynes@359
    41
    int active;  /* 0 = deleted, 1 = normal. 2 = accessed (temp-space only) */
nkeynes@359
    42
    uint32_t size;
nkeynes@359
    43
    void **lut_entry; /* For deletion */
nkeynes@571
    44
    xlat_recovery_record_t recover_table;
nkeynes@571
    45
    uint32_t recover_table_size;
nkeynes@359
    46
    unsigned char code[0];
nkeynes@580
    47
} __attribute__((packed));
nkeynes@580
    48
nkeynes@580
    49
typedef struct xlat_cache_block *xlat_cache_block_t;
nkeynes@359
    50
nkeynes@359
    51
/**
nkeynes@422
    52
 * Initialize the translation cache
nkeynes@422
    53
 */
nkeynes@422
    54
void xlat_cache_init(void);
nkeynes@422
    55
nkeynes@422
    56
/**
nkeynes@359
    57
 * Returns the next block in the new cache list that can be written to by the
nkeynes@359
    58
 * translator.
nkeynes@359
    59
 */
nkeynes@359
    60
xlat_cache_block_t xlat_start_block(sh4addr_t address);
nkeynes@359
    61
nkeynes@359
    62
/**
nkeynes@359
    63
 * Increases the current block size (only valid between calls to xlat_start_block()
nkeynes@359
    64
 * and xlat_commit_block()). 
nkeynes@359
    65
 * @return the new block, which may be different from the old block.
nkeynes@359
    66
 */
nkeynes@410
    67
xlat_cache_block_t xlat_extend_block( uint32_t newSize );
nkeynes@359
    68
nkeynes@359
    69
/**
nkeynes@359
    70
 * Commit the current translation block
nkeynes@359
    71
 * @param addr target address (for the lookup table)
nkeynes@359
    72
 * @param destsize final size of the translation in bytes.
nkeynes@359
    73
 * @param srcsize size of the original data that was translated in bytes
nkeynes@359
    74
 */
nkeynes@359
    75
void xlat_commit_block( uint32_t destsize, uint32_t srcsize );
nkeynes@359
    76
nkeynes@359
    77
/**
nkeynes@376
    78
 * Dump the disassembly of the specified code block to a stream
nkeynes@376
    79
 * (primarily for debugging purposes)
nkeynes@376
    80
 * @param out The stream to write the output to
nkeynes@376
    81
 * @param code a translated block
nkeynes@376
    82
 */
nkeynes@376
    83
void xlat_disasm_block( FILE *out, void *code );
nkeynes@376
    84
nkeynes@376
    85
nkeynes@376
    86
/**
nkeynes@359
    87
 * Delete (deactivate) the specified block from the cache. Caller is responsible
nkeynes@359
    88
 * for ensuring that there really is a block there.
nkeynes@359
    89
 */
nkeynes@359
    90
void xlat_delete_block( xlat_cache_block_t block );
nkeynes@359
    91
nkeynes@359
    92
/**
nkeynes@359
    93
 * Retrieve the entry point for the translated code corresponding to the given
nkeynes@359
    94
 * SH4 address, or NULL if there is no code for that address.
nkeynes@359
    95
 */
nkeynes@359
    96
void *xlat_get_code( sh4addr_t address );
nkeynes@359
    97
nkeynes@359
    98
/**
nkeynes@571
    99
 * Retrieve the recovery record corresponding to the given
nkeynes@571
   100
 * native address, or NULL if there is no recovery code for the address.
nkeynes@571
   101
 * @param code The code block containing the recovery table.
nkeynes@571
   102
 * @param native_pc A pointer that must be within the currently executing 
nkeynes@571
   103
 * @param recover_after If TRUE, return the first record after the given pc, otherwise
nkeynes@571
   104
 * return the first record before or equal to the given pc.
nkeynes@571
   105
 * translation block.
nkeynes@571
   106
 */
nkeynes@571
   107
struct xlat_recovery_record *xlat_get_recovery( void *code, void *native_pc, gboolean recover_after );
nkeynes@571
   108
nkeynes@571
   109
/**
nkeynes@569
   110
 * Retrieve the entry point for the translated code corresponding to the given
nkeynes@569
   111
 * SH4 virtual address, or NULL if there is no code for the address. 
nkeynes@569
   112
 * If the virtual address cannot be resolved, this method will raise a TLB miss 
nkeynes@569
   113
 * exception, and return NULL.
nkeynes@569
   114
 */
nkeynes@569
   115
void *xlat_get_code_by_vma( sh4vma_t address );
nkeynes@569
   116
nkeynes@569
   117
/**
nkeynes@407
   118
 * Retrieve the address of the lookup table entry corresponding to the
nkeynes@407
   119
 * given SH4 address.
nkeynes@407
   120
 */
nkeynes@407
   121
void **xlat_get_lut_entry( sh4addr_t address );
nkeynes@407
   122
nkeynes@407
   123
/**
nkeynes@571
   124
 * Retrieve the current host address of the running translated code block.
nkeynes@571
   125
 * @return the host PC, or null if there is no currently executing translated
nkeynes@571
   126
 * block (or the stack is corrupted)
nkeynes@571
   127
 * Note: this method is implemented in host-specific asm.
nkeynes@571
   128
 */
nkeynes@571
   129
void *xlat_get_native_pc();
nkeynes@571
   130
nkeynes@571
   131
/**
nkeynes@571
   132
 * Retrieve the size of the block starting at the specified pointer. If the
nkeynes@366
   133
 * pointer is not a valid code block, the return value is undefined.
nkeynes@366
   134
 */
nkeynes@366
   135
uint32_t xlat_get_block_size( void *ptr );
nkeynes@366
   136
nkeynes@366
   137
/**
nkeynes@571
   138
 * Retrieve the size of the code in the block starting at the specified 
nkeynes@571
   139
 * pointer. Effectively this is xlat_get_block_size() minus the size of
nkeynes@571
   140
 * the recovery table. If the pointer is not a valid code block, the 
nkeynes@571
   141
 * return value is undefined.
nkeynes@571
   142
 */
nkeynes@571
   143
uint32_t xlat_get_code_size( void *ptr );
nkeynes@571
   144
nkeynes@571
   145
/**
nkeynes@359
   146
 * Flush the code cache for the page containing the given address
nkeynes@359
   147
 */
nkeynes@359
   148
void xlat_flush_page( sh4addr_t address );
nkeynes@359
   149
nkeynes@400
   150
void xlat_invalidate_word( sh4addr_t address );
nkeynes@400
   151
void xlat_invalidate_long( sh4addr_t address );
nkeynes@400
   152
nkeynes@400
   153
nkeynes@400
   154
/**
nkeynes@400
   155
 * Invalidate the code cache for a memory region
nkeynes@400
   156
 */
nkeynes@400
   157
void xlat_invalidate_block( sh4addr_t address, size_t bytes );
nkeynes@400
   158
nkeynes@359
   159
/**
nkeynes@359
   160
 * Flush the entire code cache. This isn't as cheap as one might like
nkeynes@359
   161
 */
nkeynes@359
   162
void xlat_flush_cache();
nkeynes@359
   163
nkeynes@359
   164
/**
nkeynes@359
   165
 * Check the internal integrity of the cache
nkeynes@359
   166
 */
nkeynes@359
   167
void xlat_check_integrity();
nkeynes@571
   168
nkeynes@571
   169
#endif /* lxdream_xltcache_H */
.