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