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