Search
lxdream.org :: lxdream/src/sh4/sh4trans.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4trans.h
changeset 1091:186558374345
prev1065:bc1cc0c54917
next1125:9dd5dee45db9
author nkeynes
date Tue Dec 15 08:46:37 2009 +1000 (11 years ago)
permissions -rw-r--r--
last change Add side-by-side x86+sh4 disassembly output
Print SH4 state information and disassembly of the current block when
crashing.
Fix delay slot instruction in conditional branch not being marked as a
delay-slot instruction in the branch-not-taken path.
Rename REG_* defines in cpu.h to avoid conflict with translation defs
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@926
    37
#define EPILOGUE_SIZE 136
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@585
    44
/**
nkeynes@359
    45
 */
nkeynes@1091
    46
uint32_t sh4_translate_run_slice( uint32_t nanosecs );
nkeynes@585
    47
nkeynes@585
    48
/**
nkeynes@669
    49
 * Initialize the translation engine (if required). Note xlat cache
nkeynes@669
    50
 * must already be initialized.
nkeynes@669
    51
 */
nkeynes@1091
    52
void sh4_translate_init( void);
nkeynes@669
    53
nkeynes@669
    54
/**
nkeynes@359
    55
 * Translate the specified block of code starting from the specified start
nkeynes@359
    56
 * address until the first branch/jump instruction.
nkeynes@359
    57
 */
nkeynes@359
    58
void *sh4_translate_basic_block( sh4addr_t start );
nkeynes@359
    59
nkeynes@669
    60
/**
nkeynes@669
    61
 * Add a recovery record for the current code generation position, with the
nkeynes@669
    62
 * specified instruction count
nkeynes@669
    63
 */
nkeynes@669
    64
void sh4_translate_add_recovery( uint32_t icount );
nkeynes@571
    65
nkeynes@359
    66
extern uint8_t *xlat_output;
nkeynes@571
    67
extern struct xlat_recovery_record xlat_recovery[MAX_RECOVERY_SIZE];
nkeynes@604
    68
extern xlat_cache_block_t xlat_current_block;
nkeynes@571
    69
extern uint32_t xlat_recovery_posn;
nkeynes@359
    70
nkeynes@526
    71
/******************************************************************************
nkeynes@526
    72
 * Code generation - these methods must be provided by the
nkeynes@526
    73
 * actual code gen (eg sh4x86.c) 
nkeynes@526
    74
 ******************************************************************************/
nkeynes@359
    75
nkeynes@527
    76
#define TARGET_X86 1
nkeynes@527
    77
nkeynes@408
    78
void sh4_translate_begin_block( sh4addr_t pc );
nkeynes@526
    79
uint32_t sh4_translate_instruction( sh4addr_t pc );
nkeynes@359
    80
void sh4_translate_end_block( sh4addr_t pc );
nkeynes@593
    81
uint32_t sh4_translate_end_block_size();
nkeynes@669
    82
void sh4_translate_emit_breakpoint( sh4vma_t pc );
nkeynes@1091
    83
void sh4_translate_crashdump();
nkeynes@571
    84
nkeynes@571
    85
typedef void (*unwind_thunk_t)(void);
nkeynes@571
    86
nkeynes@571
    87
/**
nkeynes@571
    88
 * From within the translator, (typically called from MMU exception handling routines)
nkeynes@571
    89
 * immediately exit the current translation block (performing cleanup as necessary) and
nkeynes@1091
    90
 * return to sh4_translate_run_slice(). Effectively a fast longjmp w/ xlat recovery.
nkeynes@571
    91
 *
nkeynes@571
    92
 * Note: The correct working of this method depends on the translator anticipating the
nkeynes@571
    93
 * exception and generating the appropriate recovery block(s) - currently this means 
nkeynes@571
    94
 * that it should ONLY be called from within the context of a memory read or write.
nkeynes@571
    95
 *
nkeynes@571
    96
 * @param is_completion If TRUE, exit after completing the current instruction (effectively),
nkeynes@571
    97
 *   otherwise abort the current instruction with no effect. 
nkeynes@571
    98
 * @param thunk A function to execute after perform xlat recovery, but before returning
nkeynes@571
    99
 * to run_slice. If NULL, control returns directly.
nkeynes@571
   100
 * @return This method never returns. 
nkeynes@571
   101
 */
nkeynes@571
   102
void sh4_translate_unwind_stack( gboolean is_completion, unwind_thunk_t thunk );
nkeynes@577
   103
nkeynes@577
   104
/**
nkeynes@740
   105
 * Called when doing a break out of the translator - finalizes the system state up to
nkeynes@740
   106
 * the end of the current instruction.
nkeynes@577
   107
 */
nkeynes@740
   108
void sh4_translate_exit_recover( );
nkeynes@591
   109
nkeynes@591
   110
/**
nkeynes@941
   111
 * Called when doing a break out of the translator following a taken exception - 
nkeynes@941
   112
 * finalizes the system state up to the start of the current instruction.
nkeynes@941
   113
 */
nkeynes@941
   114
void sh4_translate_exception_exit_recover( );
nkeynes@941
   115
nkeynes@941
   116
/**
nkeynes@669
   117
 * From within the translator, exit the current block at the end of the 
nkeynes@740
   118
 * current instruction, flush the translation cache (completely) 
nkeynes@740
   119
 * @return TRUE to perform a vm-exit/continue after the flush
nkeynes@669
   120
 */
nkeynes@740
   121
gboolean sh4_translate_flush_cache( void );
nkeynes@669
   122
nkeynes@669
   123
/**
nkeynes@591
   124
 * Support function called from the translator when a breakpoint is hit.
nkeynes@591
   125
 * Either returns immediately (to skip the breakpoint), or aborts the current
nkeynes@591
   126
 * cycle and never returns.
nkeynes@591
   127
 */
nkeynes@905
   128
void FASTCALL sh4_translate_breakpoint_hit( sh4vma_t pc );
nkeynes@736
   129
nkeynes@1091
   130
/**
nkeynes@1091
   131
 * Disassemble the given translated code block, and it's source SH4 code block
nkeynes@1091
   132
 * side-by-side. The current native pc will be marked if non-null.
nkeynes@1091
   133
 */
nkeynes@1091
   134
void sh4_translate_disasm_block( FILE *out, void *code, sh4addr_t source_start, void *native_pc );
nkeynes@1091
   135
nkeynes@736
   136
#ifdef __cplusplus
nkeynes@736
   137
}
nkeynes@736
   138
#endif
nkeynes@736
   139
nkeynes@760
   140
#endif /* !lxdream_sh4trans_H */
.