Search
lxdream.org :: lxdream/src/sh4/sh4trans.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4trans.h
changeset 736:a02d1475ccfd
prev733:633ee022f52e
next740:dd11269ee48b
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (13 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
file annotate diff log raw
nkeynes@359
     1
/**
nkeynes@586
     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@586
    22
#include "sh4/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@707
    33
#define MAX_INSTRUCTION_SIZE 384
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@410
    37
#define EPILOGUE_SIZE 128
nkeynes@586
    38
nkeynes@586
    39
/** Maximum number of recovery records for a translated block (2048 based on
nkeynes@586
    40
 * 1 record per SH4 instruction in a 4K page).
nkeynes@586
    41
 */
nkeynes@733
    42
#define MAX_RECOVERY_SIZE 2049
nkeynes@586
    43
nkeynes@359
    44
/**
nkeynes@586
    45
 * Translation flag - exit the current block but continue (eg exception handling)
nkeynes@586
    46
 */
nkeynes@586
    47
#define XLAT_EXIT_CONTINUE 1
nkeynes@359
    48
nkeynes@586
    49
/**
nkeynes@586
    50
 * Translation flag - exit the current block and halt immediately (eg fatal error)
nkeynes@586
    51
 */
nkeynes@586
    52
#define XLAT_EXIT_HALT 2
nkeynes@586
    53
nkeynes@586
    54
/**
nkeynes@586
    55
 * Translation flag - exit the current block and halt immediately for a system
nkeynes@586
    56
 * breakpoint.
nkeynes@586
    57
 */
nkeynes@586
    58
#define XLAT_EXIT_BREAKPOINT 3
nkeynes@586
    59
nkeynes@586
    60
/**
nkeynes@586
    61
 * Translation flag - exit the current block and continue after performing a full
nkeynes@586
    62
 * system reset (dreamcast_reset())
nkeynes@586
    63
 */
nkeynes@586
    64
#define XLAT_EXIT_SYSRESET 4
nkeynes@586
    65
nkeynes@586
    66
/**
nkeynes@617
    67
 * Translation flag - exit the current block and continue after the next IRQ.
nkeynes@617
    68
 */
nkeynes@617
    69
#define XLAT_EXIT_SLEEP 5
nkeynes@617
    70
nkeynes@617
    71
/**
nkeynes@359
    72
 */
nkeynes@359
    73
uint32_t sh4_xlat_run_slice( uint32_t nanosecs );
nkeynes@359
    74
nkeynes@359
    75
/**
nkeynes@586
    76
 * Return true if translated code is currently running
nkeynes@586
    77
 */
nkeynes@586
    78
gboolean sh4_xlat_is_running();
nkeynes@586
    79
nkeynes@586
    80
/**
nkeynes@669
    81
 * Initialize the translation engine (if required). Note xlat cache
nkeynes@669
    82
 * must already be initialized.
nkeynes@669
    83
 */
nkeynes@669
    84
void sh4_xlat_init();
nkeynes@669
    85
nkeynes@669
    86
/**
nkeynes@359
    87
 * Translate the specified block of code starting from the specified start
nkeynes@359
    88
 * address until the first branch/jump instruction.
nkeynes@359
    89
 */
nkeynes@359
    90
void *sh4_translate_basic_block( sh4addr_t start );
nkeynes@359
    91
nkeynes@669
    92
/**
nkeynes@669
    93
 * Add a recovery record for the current code generation position, with the
nkeynes@669
    94
 * specified instruction count
nkeynes@669
    95
 */
nkeynes@669
    96
void sh4_translate_add_recovery( uint32_t icount );
nkeynes@586
    97
nkeynes@359
    98
extern uint8_t *xlat_output;
nkeynes@586
    99
extern struct xlat_recovery_record xlat_recovery[MAX_RECOVERY_SIZE];
nkeynes@604
   100
extern xlat_cache_block_t xlat_current_block;
nkeynes@586
   101
extern uint32_t xlat_recovery_posn;
nkeynes@359
   102
nkeynes@526
   103
/******************************************************************************
nkeynes@526
   104
 * Code generation - these methods must be provided by the
nkeynes@526
   105
 * actual code gen (eg sh4x86.c) 
nkeynes@526
   106
 ******************************************************************************/
nkeynes@359
   107
nkeynes@527
   108
#define TARGET_X86 1
nkeynes@527
   109
nkeynes@669
   110
void sh4_translate_init( void );
nkeynes@408
   111
void sh4_translate_begin_block( sh4addr_t pc );
nkeynes@526
   112
uint32_t sh4_translate_instruction( sh4addr_t pc );
nkeynes@359
   113
void sh4_translate_end_block( sh4addr_t pc );
nkeynes@593
   114
uint32_t sh4_translate_end_block_size();
nkeynes@669
   115
void sh4_translate_emit_breakpoint( sh4vma_t pc );
nkeynes@586
   116
nkeynes@586
   117
typedef void (*unwind_thunk_t)(void);
nkeynes@586
   118
nkeynes@586
   119
/**
nkeynes@586
   120
 * From within the translator, (typically called from MMU exception handling routines)
nkeynes@586
   121
 * immediately exit the current translation block (performing cleanup as necessary) and
nkeynes@586
   122
 * return to sh4_xlat_run_slice(). Effectively a fast longjmp w/ xlat recovery.
nkeynes@586
   123
 *
nkeynes@586
   124
 * Note: The correct working of this method depends on the translator anticipating the
nkeynes@586
   125
 * exception and generating the appropriate recovery block(s) - currently this means 
nkeynes@586
   126
 * that it should ONLY be called from within the context of a memory read or write.
nkeynes@586
   127
 *
nkeynes@586
   128
 * @param is_completion If TRUE, exit after completing the current instruction (effectively),
nkeynes@586
   129
 *   otherwise abort the current instruction with no effect. 
nkeynes@586
   130
 * @param thunk A function to execute after perform xlat recovery, but before returning
nkeynes@586
   131
 * to run_slice. If NULL, control returns directly.
nkeynes@586
   132
 * @return This method never returns. 
nkeynes@586
   133
 */
nkeynes@586
   134
void sh4_translate_unwind_stack( gboolean is_completion, unwind_thunk_t thunk );
nkeynes@586
   135
nkeynes@586
   136
/**
nkeynes@586
   137
 * From within the translator, immediately exit the current translation block with
nkeynes@586
   138
 * the specified exit code (one of the XLAT_EXIT_* values).
nkeynes@586
   139
 */
nkeynes@586
   140
void sh4_translate_exit( int exit_code );
nkeynes@591
   141
nkeynes@591
   142
/**
nkeynes@669
   143
 * From within the translator, exit the current block at the end of the 
nkeynes@669
   144
 * current instruction, flush the translation cache (completely) and return
nkeynes@669
   145
 * control to sh4_xlat_run_slice.
nkeynes@669
   146
 */
nkeynes@669
   147
void sh4_translate_flush_cache( void );
nkeynes@669
   148
nkeynes@669
   149
/**
nkeynes@591
   150
 * Support function called from the translator when a breakpoint is hit.
nkeynes@591
   151
 * Either returns immediately (to skip the breakpoint), or aborts the current
nkeynes@591
   152
 * cycle and never returns.
nkeynes@591
   153
 */
nkeynes@591
   154
void sh4_translate_breakpoint_hit( sh4vma_t pc );
nkeynes@736
   155
nkeynes@736
   156
#ifdef __cplusplus
nkeynes@736
   157
}
nkeynes@736
   158
#endif
nkeynes@736
   159
nkeynes@736
   160
#endif /* !lxdream_sh4trans_H */
.