Search
lxdream.org :: lxdream/src/sh4/sh4trans.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4trans.h
changeset 577:a181aeacd6e8
prev571:9bc09948d0f2
next585:371342a39c09
author nkeynes
date Mon Jan 14 10:23:49 2008 +0000 (15 years ago)
branchlxdream-mmu
permissions -rw-r--r--
last change Remove asm file and convert to inline (easier to cope with platform conventions)
Add breakpoint support
Add MMU store-queue support
file annotate diff log raw
nkeynes@359
     1
/**
nkeynes@561
     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@571
    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@571
    31
nkeynes@571
    32
/** Maximum number of recovery records for a translated block (2048 based on
nkeynes@571
    33
 * 1 record per SH4 instruction in a 4K page).
nkeynes@571
    34
 */
nkeynes@571
    35
#define MAX_RECOVERY_SIZE 2048
nkeynes@571
    36
nkeynes@359
    37
/**
nkeynes@577
    38
 * Translation flag - exit the current block but continue (eg exception handling)
nkeynes@577
    39
 */
nkeynes@577
    40
#define XLAT_EXIT_CONTINUE 1
nkeynes@577
    41
nkeynes@577
    42
/**
nkeynes@577
    43
 * Translation flag - exit the current block and halt immediately (eg fatal error)
nkeynes@577
    44
 */
nkeynes@577
    45
#define XLAT_EXIT_HALT 2
nkeynes@577
    46
nkeynes@577
    47
/**
nkeynes@577
    48
 * Translation flag - exit the current block and halt immediately for a system
nkeynes@577
    49
 * breakpoint.
nkeynes@577
    50
 */
nkeynes@577
    51
#define XLAT_EXIT_BREAKPOINT 3
nkeynes@577
    52
nkeynes@577
    53
/**
nkeynes@359
    54
 */
nkeynes@359
    55
uint32_t sh4_xlat_run_slice( uint32_t nanosecs );
nkeynes@359
    56
nkeynes@359
    57
/**
nkeynes@359
    58
 * Translate the specified block of code starting from the specified start
nkeynes@359
    59
 * address until the first branch/jump instruction.
nkeynes@359
    60
 */
nkeynes@359
    61
void *sh4_translate_basic_block( sh4addr_t start );
nkeynes@359
    62
nkeynes@571
    63
nkeynes@359
    64
extern uint8_t *xlat_output;
nkeynes@571
    65
extern struct xlat_recovery_record xlat_recovery[MAX_RECOVERY_SIZE];
nkeynes@571
    66
extern uint32_t xlat_recovery_posn;
nkeynes@359
    67
nkeynes@526
    68
/******************************************************************************
nkeynes@526
    69
 * Code generation - these methods must be provided by the
nkeynes@526
    70
 * actual code gen (eg sh4x86.c) 
nkeynes@526
    71
 ******************************************************************************/
nkeynes@359
    72
nkeynes@527
    73
#define TARGET_X86 1
nkeynes@527
    74
#define TARGET_X86_64 2
nkeynes@527
    75
nkeynes@408
    76
void sh4_translate_begin_block( sh4addr_t pc );
nkeynes@526
    77
uint32_t sh4_translate_instruction( sh4addr_t pc );
nkeynes@359
    78
void sh4_translate_end_block( sh4addr_t pc );
nkeynes@571
    79
nkeynes@571
    80
typedef void (*unwind_thunk_t)(void);
nkeynes@571
    81
nkeynes@571
    82
/**
nkeynes@571
    83
 * From within the translator, (typically called from MMU exception handling routines)
nkeynes@571
    84
 * immediately exit the current translation block (performing cleanup as necessary) and
nkeynes@571
    85
 * return to sh4_xlat_run_slice(). Effectively a fast longjmp w/ xlat recovery.
nkeynes@571
    86
 *
nkeynes@571
    87
 * Note: The correct working of this method depends on the translator anticipating the
nkeynes@571
    88
 * exception and generating the appropriate recovery block(s) - currently this means 
nkeynes@571
    89
 * that it should ONLY be called from within the context of a memory read or write.
nkeynes@571
    90
 *
nkeynes@571
    91
 * @param is_completion If TRUE, exit after completing the current instruction (effectively),
nkeynes@571
    92
 *   otherwise abort the current instruction with no effect. 
nkeynes@571
    93
 * @param thunk A function to execute after perform xlat recovery, but before returning
nkeynes@571
    94
 * to run_slice. If NULL, control returns directly.
nkeynes@571
    95
 * @return This method never returns. 
nkeynes@571
    96
 */
nkeynes@571
    97
void sh4_translate_unwind_stack( gboolean is_completion, unwind_thunk_t thunk );
nkeynes@577
    98
nkeynes@577
    99
/**
nkeynes@577
   100
 * From within the translator, immediately exit the current translation block with
nkeynes@577
   101
 * the specified exit code (one of the XLAT_EXIT_* values).
nkeynes@577
   102
 */
nkeynes@577
   103
void sh4_translate_exit( int exit_code );
.