2 * $Id: sh4trans.c,v 1.1 2007-08-23 12:33:27 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 for( ; sh4r.slice_cycle < nanosecs && result != 0; sh4r.slice_cycle ) {
41 if( SH4_EVENT_PENDING() ) {
42 if( sh4r.event_types & PENDING_EVENT ) {
45 /* Eventq execute may (quite likely) deliver an immediate IRQ */
46 if( sh4r.event_types & PENDING_IRQ ) {
47 sh4_accept_interrupt();
51 int (*code)() = xlat_get_code(sh4r.pc);
53 code = sh4_translate_basic_block( sh4r.pc );
56 sh4r.slice_cycle += result;
59 /* If we aborted early, but the cpu is still technically running,
60 * we're doing a hard abort - cut the timeslice back to what we
63 if( sh4r.slice_cycle < nanosecs && sh4r.sh4_state == SH4_STATE_RUNNING ) {
64 nanosecs = sh4r.slice_cycle;
66 if( sh4r.sh4_state != SH4_STATE_STANDBY ) {
67 TMU_run_slice( nanosecs );
68 SCIF_run_slice( nanosecs );
76 * Translate a linear basic block, ie all instructions from the start address
77 * (inclusive) until the next branch/jump instruction or the end of the page
79 * @return the address of the translated block
80 * eg due to lack of buffer space.
82 void * sh4_translate_basic_block( sh4addr_t start )
86 xlat_cache_block_t block = xlat_start_block( start );
87 xlat_output = (uint8_t *)block->code;
88 uint8_t *eob = xlat_output + block->size;
89 sh4_translate_begin_block();
91 while( (done = sh4_x86_translate_instruction( pc )) == 0 ) {
92 if( eob - xlat_output < MAX_INSTRUCTION_SIZE ) {
93 uint8_t *oldstart = block->code;
94 block = xlat_extend_block();
95 xlat_output = block->code + (xlat_output - oldstart);
96 eob = block->code + block->size;
100 sh4_translate_end_block(done);
101 xlat_commit_block( xlat_output - block->size, pc-start );
.