Search
lxdream.org :: lxdream/src/sh4/xltcache.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/xltcache.h
changeset 906:268ea359f884
prev905:4c17ebd9ef5e
next936:f394309c399a
next953:f4a156508ad1
author nkeynes
date Fri Oct 31 03:24:49 2008 +0000 (15 years ago)
permissions -rw-r--r--
last change Remove FASTCALL from mem_copy_*, not really helping atm (and sometimes hurting)
file annotate diff log raw
nkeynes@359
     1
/**
nkeynes@586
     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@586
    22
#ifndef lxdream_xltcache_H
nkeynes@736
    23
#define lxdream_xltcache_H 1
nkeynes@586
    24
nkeynes@586
    25
/**
nkeynes@586
    26
 * For now, recovery is purely a matter of mapping native pc => sh4 pc,
nkeynes@586
    27
 * and updating sh4r.pc & sh4r.slice_cycles accordingly. In future more
nkeynes@586
    28
 * detailed recovery may be required if the translator optimizes more
nkeynes@586
    29
 * agressively.
nkeynes@586
    30
 *
nkeynes@586
    31
 * The recovery table contains (at least) one entry per abortable instruction,
nkeynes@586
    32
 * 
nkeynes@586
    33
 */
nkeynes@586
    34
typedef struct xlat_recovery_record {
nkeynes@596
    35
    uint32_t xlat_offset;    // native (translated) pc 
nkeynes@736
    36
    uint32_t sh4_icount;     // instruction number of the corresponding SH4 instruction
nkeynes@736
    37
                             // (0 = first instruction, 1 = second instruction, ... )
nkeynes@586
    38
} *xlat_recovery_record_t;
nkeynes@586
    39
nkeynes@586
    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@901
    44
    uint32_t fpscr_mask, fpscr; /* fpscr condition check */
nkeynes@592
    45
    uint32_t recover_table_offset; // Offset from code[0] of the recovery table;
nkeynes@586
    46
    uint32_t recover_table_size;
nkeynes@359
    47
    unsigned char code[0];
nkeynes@586
    48
} __attribute__((packed));
nkeynes@586
    49
nkeynes@586
    50
typedef struct xlat_cache_block *xlat_cache_block_t;
nkeynes@359
    51
nkeynes@901
    52
#define XLAT_BLOCK_FOR_CODE(code) (((xlat_cache_block_t)code)-1)
nkeynes@901
    53
nkeynes@901
    54
#define XLAT_BLOCK_FPSCR_MASK(code) (XLAT_BLOCK_FOR_CODE(code)->fpscr_mask) 
nkeynes@901
    55
#define XLAT_BLOCK_FPSCR(code) (XLAT_BLOCK_FOR_CODE(code)->fpscr_mask) 
nkeynes@901
    56
nkeynes@359
    57
/**
nkeynes@422
    58
 * Initialize the translation cache
nkeynes@422
    59
 */
nkeynes@422
    60
void xlat_cache_init(void);
nkeynes@422
    61
nkeynes@422
    62
/**
nkeynes@359
    63
 * Returns the next block in the new cache list that can be written to by the
nkeynes@359
    64
 * translator.
nkeynes@359
    65
 */
nkeynes@359
    66
xlat_cache_block_t xlat_start_block(sh4addr_t address);
nkeynes@359
    67
nkeynes@359
    68
/**
nkeynes@359
    69
 * Increases the current block size (only valid between calls to xlat_start_block()
nkeynes@359
    70
 * and xlat_commit_block()). 
nkeynes@359
    71
 * @return the new block, which may be different from the old block.
nkeynes@359
    72
 */
nkeynes@410
    73
xlat_cache_block_t xlat_extend_block( uint32_t newSize );
nkeynes@359
    74
nkeynes@359
    75
/**
nkeynes@359
    76
 * Commit the current translation block
nkeynes@359
    77
 * @param addr target address (for the lookup table)
nkeynes@359
    78
 * @param destsize final size of the translation in bytes.
nkeynes@359
    79
 * @param srcsize size of the original data that was translated in bytes
nkeynes@359
    80
 */
nkeynes@359
    81
void xlat_commit_block( uint32_t destsize, uint32_t srcsize );
nkeynes@359
    82
nkeynes@359
    83
/**
nkeynes@376
    84
 * Dump the disassembly of the specified code block to a stream
nkeynes@376
    85
 * (primarily for debugging purposes)
nkeynes@376
    86
 * @param out The stream to write the output to
nkeynes@376
    87
 * @param code a translated block
nkeynes@376
    88
 */
nkeynes@376
    89
void xlat_disasm_block( FILE *out, void *code );
nkeynes@376
    90
nkeynes@376
    91
nkeynes@376
    92
/**
nkeynes@359
    93
 * Delete (deactivate) the specified block from the cache. Caller is responsible
nkeynes@359
    94
 * for ensuring that there really is a block there.
nkeynes@359
    95
 */
nkeynes@359
    96
void xlat_delete_block( xlat_cache_block_t block );
nkeynes@359
    97
nkeynes@359
    98
/**
nkeynes@359
    99
 * Retrieve the entry point for the translated code corresponding to the given
nkeynes@359
   100
 * SH4 address, or NULL if there is no code for that address.
nkeynes@359
   101
 */
nkeynes@905
   102
void * FASTCALL xlat_get_code( sh4addr_t address );
nkeynes@359
   103
nkeynes@359
   104
/**
nkeynes@809
   105
 * Retrieve the post-instruction recovery record corresponding to the given
nkeynes@586
   106
 * native address, or NULL if there is no recovery code for the address.
nkeynes@586
   107
 * @param code The code block containing the recovery table.
nkeynes@586
   108
 * @param native_pc A pointer that must be within the currently executing 
nkeynes@809
   109
 * @param with_terminal If false, return NULL instead of the final block record. 
nkeynes@586
   110
 * return the first record before or equal to the given pc.
nkeynes@586
   111
 * translation block.
nkeynes@586
   112
 */
nkeynes@809
   113
struct xlat_recovery_record *xlat_get_post_recovery( void *code, void *native_pc, gboolean with_terminal );
nkeynes@809
   114
nkeynes@809
   115
/**
nkeynes@809
   116
 * Retrieve the pre-instruction recovery record corresponding to the given
nkeynes@809
   117
 * native address, or NULL if there is no recovery code for the address.
nkeynes@809
   118
 * @param code The code block containing the recovery table.
nkeynes@809
   119
 * @param native_pc A pointer that must be within the currently executing 
nkeynes@809
   120
 * @param with_terminal If false, return NULL instead of the final block record. 
nkeynes@809
   121
 * return the first record before or equal to the given pc.
nkeynes@809
   122
 * translation block.
nkeynes@809
   123
 */
nkeynes@809
   124
struct xlat_recovery_record *xlat_get_pre_recovery( void *code, void *native_pc );
nkeynes@809
   125
nkeynes@586
   126
nkeynes@586
   127
/**
nkeynes@586
   128
 * Retrieve the entry point for the translated code corresponding to the given
nkeynes@586
   129
 * SH4 virtual address, or NULL if there is no code for the address. 
nkeynes@586
   130
 * If the virtual address cannot be resolved, this method will raise a TLB miss 
nkeynes@586
   131
 * exception, and return NULL.
nkeynes@586
   132
 */
nkeynes@905
   133
void * FASTCALL xlat_get_code_by_vma( sh4vma_t address );
nkeynes@586
   134
nkeynes@586
   135
/**
nkeynes@407
   136
 * Retrieve the address of the lookup table entry corresponding to the
nkeynes@407
   137
 * given SH4 address.
nkeynes@407
   138
 */
nkeynes@905
   139
void ** FASTCALL xlat_get_lut_entry( sh4addr_t address );
nkeynes@407
   140
nkeynes@407
   141
/**
nkeynes@586
   142
 * Retrieve the current host address of the running translated code block.
nkeynes@586
   143
 * @return the host PC, or null if there is no currently executing translated
nkeynes@586
   144
 * block (or the stack is corrupted)
nkeynes@906
   145
 * Note: the implementation of this method is host (and calling-convention) specific.
nkeynes@906
   146
 * @param block_start start of the block the PC should be in
nkeynes@906
   147
 * @param block_size size of the code block in bytes.
nkeynes@586
   148
 */
nkeynes@906
   149
void *xlat_get_native_pc( void *block_start, uint32_t block_size );
nkeynes@586
   150
nkeynes@586
   151
/**
nkeynes@586
   152
 * Retrieve the size of the block starting at the specified pointer. If the
nkeynes@366
   153
 * pointer is not a valid code block, the return value is undefined.
nkeynes@366
   154
 */
nkeynes@905
   155
uint32_t FASTCALL xlat_get_block_size( void *ptr );
nkeynes@366
   156
nkeynes@366
   157
/**
nkeynes@586
   158
 * Retrieve the size of the code in the block starting at the specified 
nkeynes@586
   159
 * pointer. Effectively this is xlat_get_block_size() minus the size of
nkeynes@586
   160
 * the recovery table. If the pointer is not a valid code block, the 
nkeynes@586
   161
 * return value is undefined.
nkeynes@586
   162
 */
nkeynes@905
   163
uint32_t FASTCALL xlat_get_code_size( void *ptr );
nkeynes@586
   164
nkeynes@586
   165
/**
nkeynes@359
   166
 * Flush the code cache for the page containing the given address
nkeynes@359
   167
 */
nkeynes@905
   168
void FASTCALL xlat_flush_page( sh4addr_t address );
nkeynes@359
   169
nkeynes@905
   170
void FASTCALL xlat_invalidate_word( sh4addr_t address );
nkeynes@905
   171
void FASTCALL xlat_invalidate_long( sh4addr_t address );
nkeynes@400
   172
nkeynes@400
   173
nkeynes@400
   174
/**
nkeynes@400
   175
 * Invalidate the code cache for a memory region
nkeynes@400
   176
 */
nkeynes@905
   177
void FASTCALL xlat_invalidate_block( sh4addr_t address, size_t bytes );
nkeynes@400
   178
nkeynes@359
   179
/**
nkeynes@359
   180
 * Flush the entire code cache. This isn't as cheap as one might like
nkeynes@359
   181
 */
nkeynes@359
   182
void xlat_flush_cache();
nkeynes@359
   183
nkeynes@359
   184
/**
nkeynes@359
   185
 * Check the internal integrity of the cache
nkeynes@359
   186
 */
nkeynes@359
   187
void xlat_check_integrity();
nkeynes@586
   188
nkeynes@586
   189
#endif /* lxdream_xltcache_H */
.