filename | src/sh4/sh4trans.h |
changeset | 591:7b9612fd2395 |
prev | 586:2a3ba82cf243 |
next | 593:6c710c7c6835 |
author | nkeynes |
date | Thu Jan 17 10:11:37 2008 +0000 (14 years ago) |
permissions | -rw-r--r-- |
last change | Add flag to skip breakpoints when it's the very first instruction of a run (ie, so executing dreamcast_run() when the current pc is a breakpoint doesn't just return immediately) |
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@586 | 19 | #include "sh4/xltcache.h" |
nkeynes@359 | 20 | #include "dream.h" |
nkeynes@359 | 21 | #include "mem.h" |
nkeynes@359 | 22 | |
nkeynes@359 | 23 | /** Maximum size of a translated instruction, in bytes. This includes potentially |
nkeynes@359 | 24 | * writing the entire epilogue |
nkeynes@359 | 25 | */ |
nkeynes@389 | 26 | #define MAX_INSTRUCTION_SIZE 256 |
nkeynes@410 | 27 | /** Maximum size of the translation epilogue (current real size is 116 bytes, so |
nkeynes@410 | 28 | * allows a little room |
nkeynes@410 | 29 | */ |
nkeynes@410 | 30 | #define EPILOGUE_SIZE 128 |
nkeynes@586 | 31 | |
nkeynes@586 | 32 | /** Maximum number of recovery records for a translated block (2048 based on |
nkeynes@586 | 33 | * 1 record per SH4 instruction in a 4K page). |
nkeynes@586 | 34 | */ |
nkeynes@586 | 35 | #define MAX_RECOVERY_SIZE 2048 |
nkeynes@586 | 36 | |
nkeynes@359 | 37 | /** |
nkeynes@586 | 38 | * Translation flag - exit the current block but continue (eg exception handling) |
nkeynes@586 | 39 | */ |
nkeynes@586 | 40 | #define XLAT_EXIT_CONTINUE 1 |
nkeynes@359 | 41 | |
nkeynes@586 | 42 | /** |
nkeynes@586 | 43 | * Translation flag - exit the current block and halt immediately (eg fatal error) |
nkeynes@586 | 44 | */ |
nkeynes@586 | 45 | #define XLAT_EXIT_HALT 2 |
nkeynes@586 | 46 | |
nkeynes@586 | 47 | /** |
nkeynes@586 | 48 | * Translation flag - exit the current block and halt immediately for a system |
nkeynes@586 | 49 | * breakpoint. |
nkeynes@586 | 50 | */ |
nkeynes@586 | 51 | #define XLAT_EXIT_BREAKPOINT 3 |
nkeynes@586 | 52 | |
nkeynes@586 | 53 | /** |
nkeynes@586 | 54 | * Translation flag - exit the current block and continue after performing a full |
nkeynes@586 | 55 | * system reset (dreamcast_reset()) |
nkeynes@586 | 56 | */ |
nkeynes@586 | 57 | #define XLAT_EXIT_SYSRESET 4 |
nkeynes@586 | 58 | |
nkeynes@586 | 59 | /** |
nkeynes@359 | 60 | */ |
nkeynes@359 | 61 | uint32_t sh4_xlat_run_slice( uint32_t nanosecs ); |
nkeynes@359 | 62 | |
nkeynes@359 | 63 | /** |
nkeynes@586 | 64 | * Return true if translated code is currently running |
nkeynes@586 | 65 | */ |
nkeynes@586 | 66 | gboolean sh4_xlat_is_running(); |
nkeynes@586 | 67 | |
nkeynes@586 | 68 | /** |
nkeynes@359 | 69 | * Translate the specified block of code starting from the specified start |
nkeynes@359 | 70 | * address until the first branch/jump instruction. |
nkeynes@359 | 71 | */ |
nkeynes@359 | 72 | void *sh4_translate_basic_block( sh4addr_t start ); |
nkeynes@359 | 73 | |
nkeynes@586 | 74 | |
nkeynes@359 | 75 | extern uint8_t *xlat_output; |
nkeynes@586 | 76 | extern struct xlat_recovery_record xlat_recovery[MAX_RECOVERY_SIZE]; |
nkeynes@586 | 77 | extern uint32_t xlat_recovery_posn; |
nkeynes@359 | 78 | |
nkeynes@526 | 79 | /****************************************************************************** |
nkeynes@526 | 80 | * Code generation - these methods must be provided by the |
nkeynes@526 | 81 | * actual code gen (eg sh4x86.c) |
nkeynes@526 | 82 | ******************************************************************************/ |
nkeynes@359 | 83 | |
nkeynes@527 | 84 | #define TARGET_X86 1 |
nkeynes@527 | 85 | #define TARGET_X86_64 2 |
nkeynes@527 | 86 | |
nkeynes@408 | 87 | void sh4_translate_begin_block( sh4addr_t pc ); |
nkeynes@526 | 88 | uint32_t sh4_translate_instruction( sh4addr_t pc ); |
nkeynes@359 | 89 | void sh4_translate_end_block( sh4addr_t pc ); |
nkeynes@586 | 90 | |
nkeynes@586 | 91 | typedef void (*unwind_thunk_t)(void); |
nkeynes@586 | 92 | |
nkeynes@586 | 93 | /** |
nkeynes@586 | 94 | * From within the translator, (typically called from MMU exception handling routines) |
nkeynes@586 | 95 | * immediately exit the current translation block (performing cleanup as necessary) and |
nkeynes@586 | 96 | * return to sh4_xlat_run_slice(). Effectively a fast longjmp w/ xlat recovery. |
nkeynes@586 | 97 | * |
nkeynes@586 | 98 | * Note: The correct working of this method depends on the translator anticipating the |
nkeynes@586 | 99 | * exception and generating the appropriate recovery block(s) - currently this means |
nkeynes@586 | 100 | * that it should ONLY be called from within the context of a memory read or write. |
nkeynes@586 | 101 | * |
nkeynes@586 | 102 | * @param is_completion If TRUE, exit after completing the current instruction (effectively), |
nkeynes@586 | 103 | * otherwise abort the current instruction with no effect. |
nkeynes@586 | 104 | * @param thunk A function to execute after perform xlat recovery, but before returning |
nkeynes@586 | 105 | * to run_slice. If NULL, control returns directly. |
nkeynes@586 | 106 | * @return This method never returns. |
nkeynes@586 | 107 | */ |
nkeynes@586 | 108 | void sh4_translate_unwind_stack( gboolean is_completion, unwind_thunk_t thunk ); |
nkeynes@586 | 109 | |
nkeynes@586 | 110 | /** |
nkeynes@586 | 111 | * From within the translator, immediately exit the current translation block with |
nkeynes@586 | 112 | * the specified exit code (one of the XLAT_EXIT_* values). |
nkeynes@586 | 113 | */ |
nkeynes@586 | 114 | void sh4_translate_exit( int exit_code ); |
nkeynes@591 | 115 | |
nkeynes@591 | 116 | /** |
nkeynes@591 | 117 | * Support function called from the translator when a breakpoint is hit. |
nkeynes@591 | 118 | * Either returns immediately (to skip the breakpoint), or aborts the current |
nkeynes@591 | 119 | * cycle and never returns. |
nkeynes@591 | 120 | */ |
nkeynes@591 | 121 | void sh4_translate_breakpoint_hit( sh4vma_t pc ); |
.