Search
lxdream.org :: lxdream/src/sh4/sh4trans.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4trans.h
changeset 1301:b76840ccf94b
prev1292:799fdd4f704a
author nkeynes
date Fri May 29 18:47:05 2015 +1000 (8 years ago)
permissions -rw-r--r--
last change Fix test case
file annotate diff log raw
nkeynes@359
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@359
     3
 * 
nkeynes@359
     4
 * SH4->x86 translation module
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@736
    19
#ifndef lxdream_sh4trans_H
nkeynes@736
    20
#define lxdream_sh4trans_H 1
nkeynes@736
    21
nkeynes@991
    22
#include "xlat/xltcache.h"
nkeynes@359
    23
#include "dream.h"
nkeynes@359
    24
#include "mem.h"
nkeynes@359
    25
nkeynes@736
    26
#ifdef __cplusplus
nkeynes@736
    27
extern "C" {
nkeynes@736
    28
#endif
nkeynes@736
    29
nkeynes@707
    30
/** Maximum size of a translated instruction, in bytes. Current worst case seems
nkeynes@707
    31
 * to be a BF/S followed by one of the long FMOVs.
nkeynes@359
    32
 */
nkeynes@835
    33
#define MAX_INSTRUCTION_SIZE 512
nkeynes@410
    34
/** Maximum size of the translation epilogue (current real size is 116 bytes, so
nkeynes@410
    35
 * allows a little room
nkeynes@410
    36
 */
nkeynes@1196
    37
#define EPILOGUE_SIZE 139
nkeynes@571
    38
nkeynes@571
    39
/** Maximum number of recovery records for a translated block (2048 based on
nkeynes@571
    40
 * 1 record per SH4 instruction in a 4K page).
nkeynes@571
    41
 */
nkeynes@733
    42
#define MAX_RECOVERY_SIZE 2049
nkeynes@585
    43
nkeynes@1125
    44
typedef void (*xlat_block_begin_callback_t)();
nkeynes@1125
    45
typedef void (*xlat_block_end_callback_t)();
nkeynes@1125
    46
nkeynes@585
    47
/**
nkeynes@359
    48
 */
nkeynes@1091
    49
uint32_t sh4_translate_run_slice( uint32_t nanosecs );
nkeynes@585
    50
nkeynes@585
    51
/**
nkeynes@669
    52
 * Initialize the translation engine (if required). Note xlat cache
nkeynes@669
    53
 * must already be initialized.
nkeynes@669
    54
 */
nkeynes@1091
    55
void sh4_translate_init( void);
nkeynes@669
    56
nkeynes@669
    57
/**
nkeynes@359
    58
 * Translate the specified block of code starting from the specified start
nkeynes@359
    59
 * address until the first branch/jump instruction.
nkeynes@359
    60
 */
nkeynes@359
    61
void *sh4_translate_basic_block( sh4addr_t start );
nkeynes@359
    62
nkeynes@669
    63
/**
nkeynes@669
    64
 * Add a recovery record for the current code generation position, with the
nkeynes@669
    65
 * specified instruction count
nkeynes@669
    66
 */
nkeynes@669
    67
void sh4_translate_add_recovery( uint32_t icount );
nkeynes@571
    68
nkeynes@1125
    69
/**
nkeynes@1292
    70
 * Enter the VM at the given translated entry point
nkeynes@1292
    71
 */
nkeynes@1292
    72
void FASTCALL (*sh4_translate_enter)(void *code);
nkeynes@1292
    73
nkeynes@1292
    74
/**
nkeynes@1125
    75
 * Initialize shadow execution mode
nkeynes@1125
    76
 */
nkeynes@1125
    77
void sh4_shadow_init( void );
nkeynes@1125
    78
nkeynes@1301
    79
/**
nkeynes@1301
    80
 * Shadow mode callbacks.
nkeynes@1301
    81
 */
nkeynes@1301
    82
void sh4_shadow_block_begin( void );
nkeynes@1301
    83
void sh4_shadow_block_end( void );
nkeynes@1301
    84
nkeynes@359
    85
extern uint8_t *xlat_output;
nkeynes@571
    86
extern struct xlat_recovery_record xlat_recovery[MAX_RECOVERY_SIZE];
nkeynes@604
    87
extern xlat_cache_block_t xlat_current_block;
nkeynes@571
    88
extern uint32_t xlat_recovery_posn;
nkeynes@359
    89
nkeynes@526
    90
/******************************************************************************
nkeynes@526
    91
 * Code generation - these methods must be provided by the
nkeynes@526
    92
 * actual code gen (eg sh4x86.c) 
nkeynes@526
    93
 ******************************************************************************/
nkeynes@359
    94
nkeynes@527
    95
#define TARGET_X86 1
nkeynes@527
    96
nkeynes@408
    97
void sh4_translate_begin_block( sh4addr_t pc );
nkeynes@526
    98
uint32_t sh4_translate_instruction( sh4addr_t pc );
nkeynes@359
    99
void sh4_translate_end_block( sh4addr_t pc );
nkeynes@593
   100
uint32_t sh4_translate_end_block_size();
nkeynes@669
   101
void sh4_translate_emit_breakpoint( sh4vma_t pc );
nkeynes@1091
   102
void sh4_translate_crashdump();
nkeynes@571
   103
nkeynes@571
   104
typedef void (*unwind_thunk_t)(void);
nkeynes@571
   105
nkeynes@571
   106
/**
nkeynes@1125
   107
 * Set instrumentation callbacks
nkeynes@1125
   108
 */
nkeynes@1125
   109
void sh4_translate_set_callbacks( xlat_block_begin_callback_t begin, xlat_block_end_callback_t end );
nkeynes@1125
   110
nkeynes@1125
   111
/**
nkeynes@1125
   112
 * Enable/disable memory optimizations that bypass the mmu
nkeynes@1125
   113
 */
nkeynes@1125
   114
void sh4_translate_set_fastmem( gboolean flag );
nkeynes@1125
   115
nkeynes@1125
   116
/**
nkeynes@1125
   117
 * Set the address spaces for the translated code.
nkeynes@1125
   118
 */
nkeynes@1125
   119
void sh4_translate_set_address_space( struct mem_region_fn **priv, struct mem_region_fn **user );
nkeynes@1125
   120
nkeynes@1125
   121
/**
nkeynes@571
   122
 * From within the translator, (typically called from MMU exception handling routines)
nkeynes@571
   123
 * immediately exit the current translation block (performing cleanup as necessary) and
nkeynes@1091
   124
 * return to sh4_translate_run_slice(). Effectively a fast longjmp w/ xlat recovery.
nkeynes@571
   125
 *
nkeynes@571
   126
 * Note: The correct working of this method depends on the translator anticipating the
nkeynes@571
   127
 * exception and generating the appropriate recovery block(s) - currently this means 
nkeynes@571
   128
 * that it should ONLY be called from within the context of a memory read or write.
nkeynes@571
   129
 *
nkeynes@571
   130
 * @param is_completion If TRUE, exit after completing the current instruction (effectively),
nkeynes@571
   131
 *   otherwise abort the current instruction with no effect. 
nkeynes@571
   132
 * @param thunk A function to execute after perform xlat recovery, but before returning
nkeynes@571
   133
 * to run_slice. If NULL, control returns directly.
nkeynes@571
   134
 * @return This method never returns. 
nkeynes@571
   135
 */
nkeynes@571
   136
void sh4_translate_unwind_stack( gboolean is_completion, unwind_thunk_t thunk );
nkeynes@577
   137
nkeynes@577
   138
/**
nkeynes@740
   139
 * Called when doing a break out of the translator - finalizes the system state up to
nkeynes@740
   140
 * the end of the current instruction.
nkeynes@577
   141
 */
nkeynes@740
   142
void sh4_translate_exit_recover( );
nkeynes@591
   143
nkeynes@591
   144
/**
nkeynes@941
   145
 * Called when doing a break out of the translator following a taken exception - 
nkeynes@941
   146
 * finalizes the system state up to the start of the current instruction.
nkeynes@941
   147
 */
nkeynes@941
   148
void sh4_translate_exception_exit_recover( );
nkeynes@941
   149
nkeynes@941
   150
/**
nkeynes@669
   151
 * From within the translator, exit the current block at the end of the 
nkeynes@740
   152
 * current instruction, flush the translation cache (completely) 
nkeynes@740
   153
 * @return TRUE to perform a vm-exit/continue after the flush
nkeynes@669
   154
 */
nkeynes@740
   155
gboolean sh4_translate_flush_cache( void );
nkeynes@669
   156
nkeynes@669
   157
/**
nkeynes@1186
   158
 * Given a block's use_list, remove all direct links to the block.
nkeynes@1186
   159
 */
nkeynes@1186
   160
void sh4_translate_unlink_block( void *use_list );
nkeynes@1186
   161
nkeynes@1186
   162
/**
nkeynes@591
   163
 * Support function called from the translator when a breakpoint is hit.
nkeynes@591
   164
 * Either returns immediately (to skip the breakpoint), or aborts the current
nkeynes@591
   165
 * cycle and never returns.
nkeynes@591
   166
 */
nkeynes@905
   167
void FASTCALL sh4_translate_breakpoint_hit( sh4vma_t pc );
nkeynes@736
   168
nkeynes@1091
   169
/**
nkeynes@1091
   170
 * Disassemble the given translated code block, and it's source SH4 code block
nkeynes@1091
   171
 * side-by-side. The current native pc will be marked if non-null.
nkeynes@1091
   172
 */
nkeynes@1091
   173
void sh4_translate_disasm_block( FILE *out, void *code, sh4addr_t source_start, void *native_pc );
nkeynes@1091
   174
nkeynes@1188
   175
/**
nkeynes@1188
   176
 * Dump the top N blocks in the SH4 translation cache
nkeynes@1188
   177
 */
nkeynes@1188
   178
void sh4_translate_dump_cache_by_activity( unsigned int topN );
nkeynes@1188
   179
nkeynes@1263
   180
/**
nkeynes@1263
   181
 * Translator function to retrieve the target block for the given PC,
nkeynes@1263
   182
 * and replace the callsite with a direct branch to the target block.
nkeynes@1263
   183
 */
nkeynes@1263
   184
void FASTCALL sh4_translate_link_block( uint32_t pc );
nkeynes@1263
   185
nkeynes@736
   186
#ifdef __cplusplus
nkeynes@736
   187
}
nkeynes@736
   188
#endif
nkeynes@736
   189
nkeynes@760
   190
#endif /* !lxdream_sh4trans_H */
.