2 * $Id: sh4trans.c,v 1.8 2007-10-08 12:06:01 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.
22 #include "sh4/sh4core.h"
23 #include "sh4/sh4trans.h"
24 #include "sh4/xltcache.h"
27 * Execute a timeslice using translated code only (ie translate/execute loop)
28 * Note this version does not support breakpoints
30 uint32_t sh4_xlat_run_slice( uint32_t nanosecs )
34 if( sh4r.sh4_state != SH4_STATE_RUNNING ) {
35 if( sh4r.event_pending < nanosecs ) {
36 sh4r.sh4_state = SH4_STATE_RUNNING;
37 sh4r.slice_cycle = sh4r.event_pending;
41 void * (*code)() = NULL;
42 while( sh4r.slice_cycle < nanosecs ) {
43 if( sh4r.event_pending <= sh4r.slice_cycle ) {
44 if( sh4r.event_types & PENDING_EVENT ) {
47 /* Eventq execute may (quite likely) deliver an immediate IRQ */
48 if( sh4r.event_types & PENDING_IRQ ) {
49 sh4_accept_interrupt();
55 if( sh4r.pc > 0xFFFFFF00 ) {
56 syscall_invoke( sh4r.pc );
57 sh4r.in_delay_slot = 0;
61 code = xlat_get_code(sh4r.pc);
63 code = sh4_translate_basic_block( sh4r.pc );
69 if( sh4r.sh4_state != SH4_STATE_STANDBY ) {
70 TMU_run_slice( nanosecs );
71 SCIF_run_slice( nanosecs );
79 * Translate a linear basic block, ie all instructions from the start address
80 * (inclusive) until the next branch/jump instruction or the end of the page
82 * @return the address of the translated block
83 * eg due to lack of buffer space.
85 void * sh4_translate_basic_block( sh4addr_t start )
88 sh4addr_t lastpc = (pc&0xFFFFF000)+0x1000;
90 xlat_cache_block_t block = xlat_start_block( start );
91 xlat_output = (uint8_t *)block->code;
92 uint8_t *eob = xlat_output + block->size;
93 sh4_translate_begin_block(pc);
96 if( eob - xlat_output < MAX_INSTRUCTION_SIZE ) {
97 uint8_t *oldstart = block->code;
98 block = xlat_extend_block( xlat_output - oldstart + MAX_INSTRUCTION_SIZE );
99 xlat_output = block->code + (xlat_output - oldstart);
100 eob = block->code + block->size;
102 done = sh4_translate_instruction( pc );
103 assert( xlat_output <= eob );
105 if ( pc >= lastpc ) {
110 if( eob - xlat_output < EPILOGUE_SIZE ) {
111 uint8_t *oldstart = block->code;
112 block = xlat_extend_block( xlat_output - oldstart + EPILOGUE_SIZE );
113 xlat_output = block->code + (xlat_output - oldstart);
115 sh4_translate_end_block(pc);
116 xlat_commit_block( xlat_output - block->code, pc-start );
121 * Translate a linear basic block to a temporary buffer, execute it, and return
122 * the result of the execution. The translation is discarded.
124 void *sh4_translate_and_run( sh4addr_t start )
126 unsigned char buf[65536];
128 sh4addr_t pc = start;
131 uint8_t *eob = xlat_output + sizeof(buf);
133 sh4_translate_begin_block(pc);
135 while( (done = sh4_translate_instruction( pc )) == 0 ) {
136 assert( (eob - xlat_output) >= MAX_INSTRUCTION_SIZE );
140 sh4_translate_end_block(pc);
142 void * (*code)() = (void *)buf;
.