4 * SH4->x86 translation module
6 * Copyright (c) 2005 Nathan Keynes.
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.
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.
19 #include "sh4/xltcache.h"
23 /** Maximum size of a translated instruction, in bytes. This includes potentially
24 * writing the entire epilogue
26 #define MAX_INSTRUCTION_SIZE 256
27 /** Maximum size of the translation epilogue (current real size is 116 bytes, so
28 * allows a little room
30 #define EPILOGUE_SIZE 128
32 /** Maximum number of recovery records for a translated block (2048 based on
33 * 1 record per SH4 instruction in a 4K page).
35 #define MAX_RECOVERY_SIZE 2048
38 * Translation flag - exit the current block but continue (eg exception handling)
40 #define XLAT_EXIT_CONTINUE 1
43 * Translation flag - exit the current block and halt immediately (eg fatal error)
45 #define XLAT_EXIT_HALT 2
48 * Translation flag - exit the current block and halt immediately for a system
51 #define XLAT_EXIT_BREAKPOINT 3
54 * Translation flag - exit the current block and continue after performing a full
55 * system reset (dreamcast_reset())
57 #define XLAT_EXIT_SYSRESET 4
61 uint32_t sh4_xlat_run_slice( uint32_t nanosecs );
64 * Return true if translated code is currently running
66 gboolean sh4_xlat_is_running();
69 * Translate the specified block of code starting from the specified start
70 * address until the first branch/jump instruction.
72 void *sh4_translate_basic_block( sh4addr_t start );
75 extern uint8_t *xlat_output;
76 extern struct xlat_recovery_record xlat_recovery[MAX_RECOVERY_SIZE];
77 extern xlat_cache_block_t xlat_current_block;
78 extern uint32_t xlat_recovery_posn;
80 /******************************************************************************
81 * Code generation - these methods must be provided by the
82 * actual code gen (eg sh4x86.c)
83 ******************************************************************************/
86 #define TARGET_X86_64 2
88 void sh4_translate_begin_block( sh4addr_t pc );
89 uint32_t sh4_translate_instruction( sh4addr_t pc );
90 void sh4_translate_end_block( sh4addr_t pc );
91 uint32_t sh4_translate_end_block_size();
93 typedef void (*unwind_thunk_t)(void);
96 * From within the translator, (typically called from MMU exception handling routines)
97 * immediately exit the current translation block (performing cleanup as necessary) and
98 * return to sh4_xlat_run_slice(). Effectively a fast longjmp w/ xlat recovery.
100 * Note: The correct working of this method depends on the translator anticipating the
101 * exception and generating the appropriate recovery block(s) - currently this means
102 * that it should ONLY be called from within the context of a memory read or write.
104 * @param is_completion If TRUE, exit after completing the current instruction (effectively),
105 * otherwise abort the current instruction with no effect.
106 * @param thunk A function to execute after perform xlat recovery, but before returning
107 * to run_slice. If NULL, control returns directly.
108 * @return This method never returns.
110 void sh4_translate_unwind_stack( gboolean is_completion, unwind_thunk_t thunk );
113 * From within the translator, immediately exit the current translation block with
114 * the specified exit code (one of the XLAT_EXIT_* values).
116 void sh4_translate_exit( int exit_code );
119 * Support function called from the translator when a breakpoint is hit.
120 * Either returns immediately (to skip the breakpoint), or aborts the current
121 * cycle and never returns.
123 void sh4_translate_breakpoint_hit( sh4vma_t pc );
.