Search
lxdream.org :: lxdream/src/sh4/sh4trans.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4trans.c
changeset 1300:d18488c8668b
prev1298:d0eb2307b847
next1301:b76840ccf94b
author nkeynes
date Wed May 27 08:46:29 2015 +1000 (5 years ago)
permissions -rw-r--r--
last change Add support for extracting the ELF symbol table and printing symbol names
alongside the SH4 disassembly
file annotate diff log raw
nkeynes@359
     1
/**
nkeynes@586
     2
 * $Id$
nkeynes@359
     3
 * 
nkeynes@359
     4
 * SH4 translation core module. This part handles the non-target-specific
nkeynes@359
     5
 * section of the translation.
nkeynes@359
     6
 *
nkeynes@359
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@359
     8
 *
nkeynes@359
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@359
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@359
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@359
    12
 * (at your option) any later version.
nkeynes@359
    13
 *
nkeynes@359
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@359
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@359
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@359
    17
 * GNU General Public License for more details.
nkeynes@359
    18
 */
nkeynes@398
    19
#include <assert.h>
nkeynes@430
    20
#include "eventq.h"
nkeynes@430
    21
#include "syscall.h"
nkeynes@586
    22
#include "clock.h"
nkeynes@669
    23
#include "dreamcast.h"
nkeynes@430
    24
#include "sh4/sh4core.h"
nkeynes@430
    25
#include "sh4/sh4trans.h"
nkeynes@975
    26
#include "sh4/sh4mmio.h"
nkeynes@1263
    27
#include "sh4/sh4dasm.h"
nkeynes@975
    28
#include "sh4/mmu.h"
nkeynes@991
    29
#include "xlat/xltcache.h"
nkeynes@1263
    30
#include "xlat/xlatdasm.h"
nkeynes@586
    31
nkeynes@1125
    32
//#define SINGLESTEP 1
nkeynes@1125
    33
nkeynes@359
    34
/**
nkeynes@359
    35
 * Execute a timeslice using translated code only (ie translate/execute loop)
nkeynes@359
    36
 */
nkeynes@740
    37
uint32_t sh4_translate_run_slice( uint32_t nanosecs ) 
nkeynes@359
    38
{
nkeynes@1112
    39
    event_schedule( EVENT_ENDTIMESLICE, nanosecs );
nkeynes@1112
    40
    for(;;) {
nkeynes@736
    41
        if( sh4r.event_pending <= sh4r.slice_cycle ) {
nkeynes@1187
    42
            sh4_handle_pending_events();
nkeynes@1112
    43
            if( sh4r.slice_cycle >= nanosecs )
nkeynes@1112
    44
                return nanosecs;
nkeynes@736
    45
        }
nkeynes@359
    46
nkeynes@1112
    47
        if( IS_SYSCALL(sh4r.pc) ) {
nkeynes@1112
    48
            uint32_t pc = sh4r.pc;
nkeynes@1112
    49
            sh4r.pc = sh4r.pr;
nkeynes@1112
    50
            sh4r.in_delay_slot = 0;
nkeynes@1112
    51
            syscall_invoke( pc );
nkeynes@1112
    52
        }
nkeynes@736
    53
nkeynes@1187
    54
        void * (*code)() = xlat_get_code_by_vma( sh4r.pc );
nkeynes@1149
    55
        if( code != NULL ) {
nkeynes@1149
    56
            while( sh4r.xlat_sh4_mode != XLAT_BLOCK_MODE(code) ) {
nkeynes@1149
    57
                code = XLAT_BLOCK_CHAIN(code);
nkeynes@1149
    58
                if( code == NULL ) {
nkeynes@1149
    59
                    code = sh4_translate_basic_block( sh4r.pc );
nkeynes@1149
    60
                    break;
nkeynes@1149
    61
                }
nkeynes@1149
    62
            }
nkeynes@1149
    63
        } else {
nkeynes@936
    64
            code = sh4_translate_basic_block( sh4r.pc );
nkeynes@736
    65
        }
nkeynes@1292
    66
        sh4_translate_enter(code);
nkeynes@359
    67
    }
nkeynes@359
    68
}
nkeynes@359
    69
nkeynes@359
    70
uint8_t *xlat_output;
nkeynes@596
    71
xlat_cache_block_t xlat_current_block;
nkeynes@586
    72
struct xlat_recovery_record xlat_recovery[MAX_RECOVERY_SIZE];
nkeynes@586
    73
uint32_t xlat_recovery_posn;
nkeynes@359
    74
nkeynes@596
    75
void sh4_translate_add_recovery( uint32_t icount )
nkeynes@596
    76
{
nkeynes@596
    77
    xlat_recovery[xlat_recovery_posn].xlat_offset = 
nkeynes@736
    78
        ((uintptr_t)xlat_output) - ((uintptr_t)xlat_current_block->code);
nkeynes@596
    79
    xlat_recovery[xlat_recovery_posn].sh4_icount = icount;
nkeynes@596
    80
    xlat_recovery_posn++;
nkeynes@596
    81
}
nkeynes@596
    82
nkeynes@359
    83
/**
nkeynes@359
    84
 * Translate a linear basic block, ie all instructions from the start address
nkeynes@359
    85
 * (inclusive) until the next branch/jump instruction or the end of the page
nkeynes@359
    86
 * is reached.
nkeynes@914
    87
 * @param start VMA of the block start (which must already be in the icache)
nkeynes@359
    88
 * @return the address of the translated block
nkeynes@359
    89
 * eg due to lack of buffer space.
nkeynes@359
    90
 */
nkeynes@359
    91
void * sh4_translate_basic_block( sh4addr_t start )
nkeynes@359
    92
{
nkeynes@408
    93
    sh4addr_t pc = start;
nkeynes@410
    94
    sh4addr_t lastpc = (pc&0xFFFFF000)+0x1000;
nkeynes@1298
    95
    int done;
nkeynes@914
    96
    xlat_current_block = xlat_start_block( GET_ICACHE_PHYS(start) );
nkeynes@596
    97
    xlat_output = (uint8_t *)xlat_current_block->code;
nkeynes@586
    98
    xlat_recovery_posn = 0;
nkeynes@596
    99
    uint8_t *eob = xlat_output + xlat_current_block->size;
nkeynes@588
   100
nkeynes@588
   101
    if( GET_ICACHE_END() < lastpc ) {
nkeynes@711
   102
        lastpc = GET_ICACHE_END();
nkeynes@588
   103
    }
nkeynes@588
   104
nkeynes@408
   105
    sh4_translate_begin_block(pc);
nkeynes@359
   106
nkeynes@408
   107
    do {
nkeynes@711
   108
        if( eob - xlat_output < MAX_INSTRUCTION_SIZE ) {
nkeynes@711
   109
            uint8_t *oldstart = xlat_current_block->code;
nkeynes@711
   110
            xlat_current_block = xlat_extend_block( xlat_output - oldstart + MAX_INSTRUCTION_SIZE );
nkeynes@711
   111
            xlat_output = xlat_current_block->code + (xlat_output - oldstart);
nkeynes@711
   112
            eob = xlat_current_block->code + xlat_current_block->size;
nkeynes@711
   113
        }
nkeynes@711
   114
        done = sh4_translate_instruction( pc ); 
nkeynes@711
   115
        assert( xlat_output <= eob );
nkeynes@711
   116
        pc += 2;
nkeynes@1195
   117
        if ( pc >= lastpc && done == 0 ) {
nkeynes@711
   118
            done = 2;
nkeynes@711
   119
        }
nkeynes@1125
   120
#ifdef SINGLESTEP
nkeynes@1125
   121
        if( !done ) done = 2;
nkeynes@1125
   122
#endif
nkeynes@408
   123
    } while( !done );
nkeynes@408
   124
    pc += (done - 2);
nkeynes@617
   125
nkeynes@617
   126
    // Add end-of-block recovery for post-instruction checks
nkeynes@617
   127
    sh4_translate_add_recovery( (pc - start)>>1 ); 
nkeynes@617
   128
nkeynes@593
   129
    int epilogue_size = sh4_translate_end_block_size();
nkeynes@593
   130
    uint32_t recovery_size = sizeof(struct xlat_recovery_record)*xlat_recovery_posn;
nkeynes@711
   131
    uint32_t finalsize = (xlat_output - xlat_current_block->code) + epilogue_size + recovery_size;
nkeynes@711
   132
    if( xlat_current_block->size < finalsize ) {
nkeynes@711
   133
        uint8_t *oldstart = xlat_current_block->code;
nkeynes@711
   134
        xlat_current_block = xlat_extend_block( finalsize );
nkeynes@711
   135
        xlat_output = xlat_current_block->code + (xlat_output - oldstart);
nkeynes@410
   136
    }	
nkeynes@368
   137
    sh4_translate_end_block(pc);
nkeynes@711
   138
    assert( xlat_output <= (xlat_current_block->code + xlat_current_block->size - recovery_size) );
nkeynes@736
   139
nkeynes@586
   140
    /* Write the recovery records onto the end of the code block */
nkeynes@586
   141
    memcpy( xlat_output, xlat_recovery, recovery_size);
nkeynes@596
   142
    xlat_current_block->recover_table_offset = xlat_output - (uint8_t *)xlat_current_block->code;
nkeynes@596
   143
    xlat_current_block->recover_table_size = xlat_recovery_posn;
nkeynes@936
   144
    xlat_current_block->xlat_sh4_mode = sh4r.xlat_sh4_mode;
nkeynes@1195
   145
    xlat_commit_block( finalsize, start, pc );
nkeynes@596
   146
    return xlat_current_block->code;
nkeynes@359
   147
}
nkeynes@359
   148
nkeynes@398
   149
/**
nkeynes@586
   150
 * "Execute" the supplied recovery record. Currently this only updates
nkeynes@586
   151
 * sh4r.pc and sh4r.slice_cycle according to the currently executing
nkeynes@586
   152
 * instruction. In future this may be more sophisticated (ie will
nkeynes@586
   153
 * call into generated code).
nkeynes@398
   154
 */
nkeynes@586
   155
void sh4_translate_run_recovery( xlat_recovery_record_t recovery )
nkeynes@398
   156
{
nkeynes@586
   157
    sh4r.slice_cycle += (recovery->sh4_icount * sh4_cpu_period);
nkeynes@586
   158
    sh4r.pc += (recovery->sh4_icount<<1);
nkeynes@586
   159
}
nkeynes@359
   160
nkeynes@941
   161
/**
nkeynes@941
   162
 * Same as sh4_translate_run_recovery, but is used to recover from a taken
nkeynes@941
   163
 * exception - that is, it fixes sh4r.spc rather than sh4r.pc
nkeynes@941
   164
 */
nkeynes@941
   165
void sh4_translate_run_exception_recovery( xlat_recovery_record_t recovery )
nkeynes@941
   166
{
nkeynes@941
   167
    sh4r.slice_cycle += (recovery->sh4_icount * sh4_cpu_period);
nkeynes@941
   168
    sh4r.spc += (recovery->sh4_icount<<1);
nkeynes@941
   169
}    
nkeynes@941
   170
nkeynes@740
   171
void sh4_translate_exit_recover( )
nkeynes@586
   172
{
nkeynes@906
   173
    void *code = xlat_get_code_by_vma( sh4r.pc );
nkeynes@906
   174
    if( code != NULL ) {
nkeynes@906
   175
        uint32_t size = xlat_get_code_size( code );
nkeynes@906
   176
        void *pc = xlat_get_native_pc( code, size );
nkeynes@906
   177
        if( pc != NULL ) {
nkeynes@906
   178
            // could be null if we're not actually running inside the translator
nkeynes@949
   179
            xlat_recovery_record_t recover = xlat_get_pre_recovery(code, pc);
nkeynes@906
   180
            if( recover != NULL ) {
nkeynes@906
   181
                // Can be null if there is no recovery necessary
nkeynes@906
   182
                sh4_translate_run_recovery(recover);
nkeynes@906
   183
            }
nkeynes@736
   184
        }
nkeynes@398
   185
    }
nkeynes@586
   186
}
nkeynes@398
   187
nkeynes@941
   188
void sh4_translate_exception_exit_recover( )
nkeynes@941
   189
{
nkeynes@941
   190
    void *code = xlat_get_code_by_vma( sh4r.spc );
nkeynes@941
   191
    if( code != NULL ) {
nkeynes@941
   192
        uint32_t size = xlat_get_code_size( code );
nkeynes@941
   193
        void *pc = xlat_get_native_pc( code, size );
nkeynes@941
   194
        if( pc != NULL ) {
nkeynes@941
   195
            // could be null if we're not actually running inside the translator
nkeynes@941
   196
            xlat_recovery_record_t recover = xlat_get_pre_recovery(code, pc);
nkeynes@941
   197
            if( recover != NULL ) {
nkeynes@941
   198
                // Can be null if there is no recovery necessary
nkeynes@941
   199
                sh4_translate_run_exception_recovery(recover);
nkeynes@941
   200
            }
nkeynes@941
   201
        }
nkeynes@941
   202
    }
nkeynes@941
   203
    
nkeynes@941
   204
}
nkeynes@941
   205
nkeynes@905
   206
void FASTCALL sh4_translate_breakpoint_hit(uint32_t pc)
nkeynes@591
   207
{
nkeynes@591
   208
    if( sh4_starting && sh4r.slice_cycle == 0 && pc == sh4r.pc ) {
nkeynes@736
   209
        return;
nkeynes@591
   210
    }
nkeynes@740
   211
    sh4_core_exit( CORE_EXIT_BREAKPOINT );
nkeynes@591
   212
}
nkeynes@591
   213
nkeynes@905
   214
void * FASTCALL xlat_get_code_by_vma( sh4vma_t vma )
nkeynes@586
   215
{
nkeynes@586
   216
    void *result = NULL;
nkeynes@586
   217
nkeynes@588
   218
    if( IS_IN_ICACHE(vma) ) {
nkeynes@736
   219
        return xlat_get_code( GET_ICACHE_PHYS(vma) );
nkeynes@586
   220
    }
nkeynes@586
   221
nkeynes@1014
   222
    if( IS_SYSCALL(vma) ) {
nkeynes@736
   223
        // lxdream hook
nkeynes@736
   224
        return NULL;
nkeynes@588
   225
    }
nkeynes@588
   226
nkeynes@588
   227
    if( !mmu_update_icache(vma) ) {
nkeynes@736
   228
        // fault - off to the fault handler
nkeynes@736
   229
        if( !mmu_update_icache(sh4r.pc) ) {
nkeynes@736
   230
            // double fault - halt
nkeynes@736
   231
            ERROR( "Double fault - halting" );
nkeynes@740
   232
            sh4_core_exit(CORE_EXIT_HALT);
nkeynes@736
   233
            return NULL;
nkeynes@736
   234
        }
nkeynes@588
   235
    }
nkeynes@588
   236
nkeynes@588
   237
    assert( IS_IN_ICACHE(sh4r.pc) );
nkeynes@588
   238
    result = xlat_get_code( GET_ICACHE_PHYS(sh4r.pc) );
nkeynes@586
   239
    return result;
nkeynes@586
   240
}
nkeynes@586
   241
nkeynes@1091
   242
/**
nkeynes@1091
   243
 * Crashdump translation information.
nkeynes@1091
   244
 *
nkeynes@1091
   245
 * Print out the currently executing block (if any), in source and target
nkeynes@1091
   246
 * assembly.
nkeynes@1091
   247
 *
nkeynes@1091
   248
 * Note: we want to be _really_ careful not to cause a second-level crash
nkeynes@1091
   249
 * at this point (e.g. if the lookup tables are corrupted...)
nkeynes@1091
   250
 */
nkeynes@1091
   251
void sh4_translate_crashdump()
nkeynes@1091
   252
{
nkeynes@1091
   253
    if( !IS_IN_ICACHE(sh4r.pc) ) {
nkeynes@1091
   254
        /** If we're crashing due to an icache lookup failure, we'll probably
nkeynes@1091
   255
         * hit this case - just complain and return.
nkeynes@1091
   256
         */
nkeynes@1091
   257
        fprintf( stderr, "** SH4 PC not in current instruction region **\n" );
nkeynes@1091
   258
        return;
nkeynes@1091
   259
    }
nkeynes@1091
   260
    uint32_t pma = GET_ICACHE_PHYS(sh4r.pc);
nkeynes@1091
   261
    void *code = xlat_get_code( pma );
nkeynes@1091
   262
    if( code == NULL ) {
nkeynes@1091
   263
        fprintf( stderr, "** No translated block for current SH4 PC **\n" );
nkeynes@1091
   264
        return;
nkeynes@1091
   265
    }
nkeynes@1091
   266
nkeynes@1091
   267
    /* Sanity check on the code pointer */
nkeynes@1091
   268
    if( !xlat_is_code_pointer(code) ) {
nkeynes@1091
   269
        fprintf( stderr, "** Possibly corrupt translation cache **\n" );
nkeynes@1091
   270
        return;
nkeynes@1091
   271
    }
nkeynes@1091
   272
nkeynes@1091
   273
    void *native_pc = xlat_get_native_pc( code, xlat_get_code_size(code) );
nkeynes@1091
   274
    sh4_translate_disasm_block( stderr, code, sh4r.pc, native_pc );
nkeynes@1091
   275
}
nkeynes@1094
   276
nkeynes@1094
   277
/**
nkeynes@1094
   278
 * Dual-dump the translated block and original SH4 code for the basic block
nkeynes@1094
   279
 * starting at sh4_pc. If there is no translated block, this prints an error
nkeynes@1094
   280
 * and returns.
nkeynes@1094
   281
 */
nkeynes@1094
   282
void sh4_translate_dump_block( uint32_t sh4_pc )
nkeynes@1094
   283
{
nkeynes@1094
   284
    if( !IS_IN_ICACHE(sh4_pc) ) {
nkeynes@1094
   285
        fprintf( stderr, "** Address %08x not in current instruction region **\n", sh4_pc );
nkeynes@1094
   286
        return;
nkeynes@1094
   287
    }
nkeynes@1094
   288
    uint32_t pma = GET_ICACHE_PHYS(sh4_pc);
nkeynes@1094
   289
    void *code = xlat_get_code( pma );
nkeynes@1094
   290
    if( code == NULL ) {
nkeynes@1094
   291
        fprintf( stderr, "** No translated block for address %08x **\n", sh4_pc );
nkeynes@1094
   292
        return;
nkeynes@1094
   293
    }
nkeynes@1094
   294
    sh4_translate_disasm_block( stderr, code, sh4_pc, NULL );
nkeynes@1094
   295
}
nkeynes@1094
   296
nkeynes@1300
   297
void sh4_translate_dump_block_phys( uint32_t sh4_pma )
nkeynes@1300
   298
{
nkeynes@1300
   299
    void *code = xlat_get_code( sh4_pma );
nkeynes@1300
   300
    if( code == NULL ) {
nkeynes@1300
   301
        fprintf( stderr, "** No translated block for address %08x **\n", sh4_pma );
nkeynes@1300
   302
        return;
nkeynes@1300
   303
    }
nkeynes@1300
   304
    sh4_translate_disasm_block( stderr, code, sh4_pma, NULL );
nkeynes@1300
   305
nkeynes@1300
   306
}
nkeynes@1263
   307
nkeynes@1263
   308
static struct xlat_symbol xlat_symbol_table[] = {
nkeynes@1263
   309
    { "sh4r+128", ((char *)&sh4r)+128 },
nkeynes@1263
   310
    { "sh4_cpu_period", &sh4_cpu_period },
nkeynes@1263
   311
    { "sh4_address_space", NULL },
nkeynes@1263
   312
    { "sh4_user_address_space", NULL },
nkeynes@1263
   313
    { "sh4_translate_breakpoint_hit", sh4_translate_breakpoint_hit },
nkeynes@1263
   314
    { "sh4_translate_link_block", sh4_translate_link_block },
nkeynes@1263
   315
    { "sh4_write_fpscr", sh4_write_fpscr },
nkeynes@1263
   316
    { "sh4_write_sr", sh4_write_sr },
nkeynes@1263
   317
    { "sh4_read_sr", sh4_read_sr },
nkeynes@1263
   318
    { "sh4_raise_exception", sh4_raise_exception },
nkeynes@1263
   319
    { "sh4_sleep", sh4_sleep },
nkeynes@1263
   320
    { "sh4_fsca", sh4_fsca },
nkeynes@1263
   321
    { "sh4_ftrv", sh4_ftrv },
nkeynes@1263
   322
    { "sh4_switch_fr_banks", sh4_switch_fr_banks },
nkeynes@1263
   323
    { "sh4_execute_instruction", sh4_execute_instruction },
nkeynes@1263
   324
    { "signsat48", signsat48 },
nkeynes@1263
   325
    { "xlat_get_code_by_vma", xlat_get_code_by_vma },
nkeynes@1263
   326
    { "xlat_get_code", xlat_get_code }
nkeynes@1263
   327
};
nkeynes@1263
   328
nkeynes@1263
   329
/**
nkeynes@1263
   330
 * Disassemble the given translated code block, and it's source code block
nkeynes@1263
   331
 * side-by-side. The current native pc will be marked if non-null.
nkeynes@1263
   332
 */
nkeynes@1263
   333
void sh4_translate_disasm_block( FILE *out, void *code, sh4addr_t source_start, void *native_pc )
nkeynes@1263
   334
{
nkeynes@1263
   335
    char buf[256];
nkeynes@1263
   336
    char op[256];
nkeynes@1263
   337
nkeynes@1263
   338
    xlat_symbol_table[2].ptr = sh4_address_space;
nkeynes@1263
   339
    xlat_symbol_table[3].ptr = sh4_user_address_space;
nkeynes@1263
   340
    xlat_disasm_init( xlat_symbol_table, sizeof(xlat_symbol_table)/sizeof(struct xlat_symbol) );
nkeynes@1263
   341
nkeynes@1263
   342
    uintptr_t target_start = (uintptr_t)code, target_pc;
nkeynes@1263
   343
    uintptr_t target_end = target_start + xlat_get_code_size(code);
nkeynes@1263
   344
    uint32_t source_pc = source_start;
nkeynes@1263
   345
    uint32_t source_end = source_pc;
nkeynes@1263
   346
    xlat_recovery_record_t source_recov_table = XLAT_RECOVERY_TABLE(code);
nkeynes@1263
   347
    xlat_recovery_record_t source_recov_end = source_recov_table + XLAT_BLOCK_FOR_CODE(code)->recover_table_size - 1;
nkeynes@1263
   348
nkeynes@1263
   349
    for( target_pc = target_start; target_pc < target_end;  ) {
nkeynes@1263
   350
        uintptr_t pc2 = xlat_disasm_instruction( target_pc, buf, sizeof(buf), op );
nkeynes@1300
   351
nkeynes@1300
   352
        if( source_recov_table < source_recov_end &&
nkeynes@1300
   353
            target_pc >= (target_start + source_recov_table->xlat_offset) ) {
nkeynes@1300
   354
            source_recov_table++;
nkeynes@1300
   355
            if( source_end < (source_start + (source_recov_table->sh4_icount)*2) )
nkeynes@1300
   356
                source_end = source_start + (source_recov_table->sh4_icount)*2;
nkeynes@1300
   357
        }
nkeynes@1300
   358
nkeynes@1300
   359
        if( source_pc < source_end ) {
nkeynes@1300
   360
        	const char *sym = sh4_disasm_get_symbol(source_pc);
nkeynes@1300
   361
        	if( sym != 0 ) {
nkeynes@1300
   362
        		fprintf( out, "%s:\n", sym );
nkeynes@1300
   363
        	}
nkeynes@1300
   364
        }
nkeynes@1263
   365
#if SIZEOF_VOID_P == 8
nkeynes@1263
   366
        fprintf( out, "%c%016lx: %-30s %-40s", (target_pc == (uintptr_t)native_pc ? '*' : ' '),
nkeynes@1263
   367
                      target_pc, op, buf );
nkeynes@1263
   368
#else
nkeynes@1263
   369
        fprintf( out, "%c%08lx: %-30s %-40s", (target_pc == (uintptr_t)native_pc ? '*' : ' '),
nkeynes@1263
   370
                      target_pc, op, buf );
nkeynes@1263
   371
#endif
nkeynes@1263
   372
nkeynes@1263
   373
        if( source_pc < source_end ) {
nkeynes@1263
   374
            uint32_t source_pc2 = sh4_disasm_instruction( source_pc, buf, sizeof(buf), op );
nkeynes@1263
   375
            fprintf( out, " %08X: %s  %s\n", source_pc, op, buf );
nkeynes@1263
   376
            source_pc = source_pc2;
nkeynes@1263
   377
        } else {
nkeynes@1263
   378
            fprintf( out, "\n" );
nkeynes@1263
   379
        }
nkeynes@1263
   380
nkeynes@1263
   381
        target_pc = pc2;
nkeynes@1263
   382
    }
nkeynes@1263
   383
nkeynes@1263
   384
    while( source_pc < source_end ) {
nkeynes@1263
   385
        uint32_t source_pc2 = sh4_disasm_instruction( source_pc, buf, sizeof(buf), op );
nkeynes@1263
   386
        fprintf( out, "%*c %08X: %s  %s\n", 72,' ', source_pc, op, buf );
nkeynes@1263
   387
        source_pc = source_pc2;
nkeynes@1263
   388
    }
nkeynes@1263
   389
}
nkeynes@1263
   390
nkeynes@1263
   391
nkeynes@1188
   392
void sh4_translate_dump_cache_by_activity( unsigned int topN )
nkeynes@1188
   393
{
nkeynes@1188
   394
    struct xlat_block_ref blocks[topN];
nkeynes@1188
   395
    topN = xlat_get_cache_blocks_by_activity(blocks, topN);
nkeynes@1188
   396
    unsigned int i;
nkeynes@1188
   397
    for( i=0; i<topN; i++ ) {
nkeynes@1188
   398
        fprintf( stderr, "0x%08X (%p): %d \n", blocks[i].pc, blocks[i].block->code, blocks[i].block->active);
nkeynes@1188
   399
        sh4_translate_disasm_block( stderr, blocks[i].block->code, blocks[i].pc, NULL );
nkeynes@1188
   400
        fprintf( stderr, "\n" );
nkeynes@1188
   401
    }
nkeynes@1188
   402
}
.