filename | src/sh4/sh4trans.h |
changeset | 675:b97020f9af1c |
prev | 669:ab344e42bca9 |
next | 707:fb7c8fe2f61c |
author | nkeynes |
date | Thu Jun 19 04:40:37 2008 +0000 (15 years ago) |
permissions | -rw-r--r-- |
last change | Refactor the gd-rom list management out of the GUI (devices, recent files, etc). Add gd-rom list to the cocoa UI. |
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 #include "sh4/xltcache.h"
20 #include "dream.h"
21 #include "mem.h"
23 /** Maximum size of a translated instruction, in bytes. This includes potentially
24 * writing the entire epilogue
25 */
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
29 */
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).
34 */
35 #define MAX_RECOVERY_SIZE 2048
37 /**
38 * Translation flag - exit the current block but continue (eg exception handling)
39 */
40 #define XLAT_EXIT_CONTINUE 1
42 /**
43 * Translation flag - exit the current block and halt immediately (eg fatal error)
44 */
45 #define XLAT_EXIT_HALT 2
47 /**
48 * Translation flag - exit the current block and halt immediately for a system
49 * breakpoint.
50 */
51 #define XLAT_EXIT_BREAKPOINT 3
53 /**
54 * Translation flag - exit the current block and continue after performing a full
55 * system reset (dreamcast_reset())
56 */
57 #define XLAT_EXIT_SYSRESET 4
59 /**
60 * Translation flag - exit the current block and continue after the next IRQ.
61 */
62 #define XLAT_EXIT_SLEEP 5
64 /**
65 */
66 uint32_t sh4_xlat_run_slice( uint32_t nanosecs );
68 /**
69 * Return true if translated code is currently running
70 */
71 gboolean sh4_xlat_is_running();
73 /**
74 * Initialize the translation engine (if required). Note xlat cache
75 * must already be initialized.
76 */
77 void sh4_xlat_init();
79 /**
80 * Translate the specified block of code starting from the specified start
81 * address until the first branch/jump instruction.
82 */
83 void *sh4_translate_basic_block( sh4addr_t start );
85 /**
86 * Add a recovery record for the current code generation position, with the
87 * specified instruction count
88 */
89 void sh4_translate_add_recovery( uint32_t icount );
91 extern uint8_t *xlat_output;
92 extern struct xlat_recovery_record xlat_recovery[MAX_RECOVERY_SIZE];
93 extern xlat_cache_block_t xlat_current_block;
94 extern uint32_t xlat_recovery_posn;
96 /******************************************************************************
97 * Code generation - these methods must be provided by the
98 * actual code gen (eg sh4x86.c)
99 ******************************************************************************/
101 #define TARGET_X86 1
103 void sh4_translate_init( void );
104 void sh4_translate_begin_block( sh4addr_t pc );
105 uint32_t sh4_translate_instruction( sh4addr_t pc );
106 void sh4_translate_end_block( sh4addr_t pc );
107 uint32_t sh4_translate_end_block_size();
108 void sh4_translate_emit_breakpoint( sh4vma_t pc );
110 typedef void (*unwind_thunk_t)(void);
112 /**
113 * From within the translator, (typically called from MMU exception handling routines)
114 * immediately exit the current translation block (performing cleanup as necessary) and
115 * return to sh4_xlat_run_slice(). Effectively a fast longjmp w/ xlat recovery.
116 *
117 * Note: The correct working of this method depends on the translator anticipating the
118 * exception and generating the appropriate recovery block(s) - currently this means
119 * that it should ONLY be called from within the context of a memory read or write.
120 *
121 * @param is_completion If TRUE, exit after completing the current instruction (effectively),
122 * otherwise abort the current instruction with no effect.
123 * @param thunk A function to execute after perform xlat recovery, but before returning
124 * to run_slice. If NULL, control returns directly.
125 * @return This method never returns.
126 */
127 void sh4_translate_unwind_stack( gboolean is_completion, unwind_thunk_t thunk );
129 /**
130 * From within the translator, immediately exit the current translation block with
131 * the specified exit code (one of the XLAT_EXIT_* values).
132 */
133 void sh4_translate_exit( int exit_code );
135 /**
136 * From within the translator, exit the current block at the end of the
137 * current instruction, flush the translation cache (completely) and return
138 * control to sh4_xlat_run_slice.
139 */
140 void sh4_translate_flush_cache( void );
142 /**
143 * Support function called from the translator when a breakpoint is hit.
144 * Either returns immediately (to skip the breakpoint), or aborts the current
145 * cycle and never returns.
146 */
147 void sh4_translate_breakpoint_hit( sh4vma_t pc );
.