2 * $Id: sh4trans.c,v 1.6 2007-09-29 11:06:40 nkeynes Exp $
4 * SH4 translation core module. This part handles the non-target-specific
5 * section of the translation.
7 * Copyright (c) 2005 Nathan Keynes.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
25 * Execute a timeslice using translated code only (ie translate/execute loop)
26 * Note this version does not support breakpoints
28 uint32_t sh4_xlat_run_slice( uint32_t nanosecs )
33 if( sh4r.sh4_state != SH4_STATE_RUNNING ) {
34 if( sh4r.event_pending < nanosecs ) {
35 sh4r.sh4_state = SH4_STATE_RUNNING;
36 sh4r.slice_cycle = sh4r.event_pending;
40 void * (*code)() = NULL;
41 while( sh4r.slice_cycle < nanosecs ) {
42 if( sh4r.event_pending <= sh4r.slice_cycle ) {
43 if( sh4r.event_types & PENDING_EVENT ) {
46 /* Eventq execute may (quite likely) deliver an immediate IRQ */
47 if( sh4r.event_types & PENDING_IRQ ) {
48 sh4_accept_interrupt();
53 if( code ) { // fast path
56 if( sh4r.pc > 0xFFFFFF00 ) {
57 syscall_invoke( sh4r.pc );
58 sh4r.in_delay_slot = 0;
62 code = xlat_get_code(sh4r.pc);
64 code = sh4_translate_basic_block( sh4r.pc );
70 if( sh4r.sh4_state != SH4_STATE_STANDBY ) {
71 TMU_run_slice( nanosecs );
72 SCIF_run_slice( nanosecs );
80 * Translate a linear basic block, ie all instructions from the start address
81 * (inclusive) until the next branch/jump instruction or the end of the page
83 * @return the address of the translated block
84 * eg due to lack of buffer space.
86 void * sh4_translate_basic_block( sh4addr_t start )
89 sh4addr_t lastpc = (pc&0xFFFFF000)+0x1000;
91 xlat_cache_block_t block = xlat_start_block( start );
92 xlat_output = (uint8_t *)block->code;
93 uint8_t *eob = xlat_output + block->size;
94 sh4_translate_begin_block(pc);
97 if( eob - xlat_output < MAX_INSTRUCTION_SIZE ) {
98 uint8_t *oldstart = block->code;
99 block = xlat_extend_block( xlat_output - oldstart + MAX_INSTRUCTION_SIZE );
100 xlat_output = block->code + (xlat_output - oldstart);
101 eob = block->code + block->size;
103 done = sh4_x86_translate_instruction( pc );
104 assert( xlat_output <= eob );
106 if ( pc >= lastpc ) {
111 if( eob - xlat_output < EPILOGUE_SIZE ) {
112 uint8_t *oldstart = block->code;
113 block = xlat_extend_block( xlat_output - oldstart + EPILOGUE_SIZE );
114 xlat_output = block->code + (xlat_output - oldstart);
116 sh4_translate_end_block(pc);
117 xlat_commit_block( xlat_output - block->code, pc-start );
122 * Translate a linear basic block to a temporary buffer, execute it, and return
123 * the result of the execution. The translation is discarded.
125 void *sh4_translate_and_run( sh4addr_t start )
132 uint8_t *eob = xlat_output + sizeof(buf);
134 sh4_translate_begin_block(pc);
136 while( (done = sh4_x86_translate_instruction( pc )) == 0 ) {
137 assert( (eob - xlat_output) >= MAX_INSTRUCTION_SIZE );
141 sh4_translate_end_block(pc);
143 void * (*code)() = (void *)buf;
.