filename | src/sh4/sh4trans.c |
changeset | 569:a1c49e1e8776 |
prev | 561:533f6b478071 |
next | 571:9bc09948d0f2 |
author | nkeynes |
date | Fri Jan 04 11:54:17 2008 +0000 (16 years ago) |
branch | lxdream-mmu |
permissions | -rw-r--r-- |
last change | Bring icache partially into line with the mmu, a little less slow with AT off now. |
view | annotate | diff | log | raw |
1 /**
2 * $Id$
3 *
4 * SH4 translation core module. This part handles the non-target-specific
5 * section of the translation.
6 *
7 * Copyright (c) 2005 Nathan Keynes.
8 *
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.
13 *
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.
18 */
19 #include <assert.h>
20 #include "eventq.h"
21 #include "syscall.h"
22 #include "sh4/sh4core.h"
23 #include "sh4/sh4trans.h"
24 #include "sh4/xltcache.h"
27 uint32_t last_pc;
28 void *last_code;
29 /**
30 * Execute a timeslice using translated code only (ie translate/execute loop)
31 * Note this version does not support breakpoints
32 */
33 uint32_t sh4_xlat_run_slice( uint32_t nanosecs )
34 {
35 sh4r.slice_cycle = 0;
37 if( sh4r.sh4_state != SH4_STATE_RUNNING ) {
38 if( sh4r.event_pending < nanosecs ) {
39 sh4r.sh4_state = SH4_STATE_RUNNING;
40 sh4r.slice_cycle = sh4r.event_pending;
41 }
42 }
44 void * (*code)() = NULL;
45 while( sh4r.slice_cycle < nanosecs ) {
46 if( sh4r.event_pending <= sh4r.slice_cycle ) {
47 if( sh4r.event_types & PENDING_EVENT ) {
48 event_execute();
49 }
50 /* Eventq execute may (quite likely) deliver an immediate IRQ */
51 if( sh4r.event_types & PENDING_IRQ ) {
52 sh4_accept_interrupt();
53 code = NULL;
54 }
55 }
57 if( code == NULL ) {
58 if( sh4r.pc > 0xFFFFFF00 ) {
59 syscall_invoke( sh4r.pc );
60 sh4r.in_delay_slot = 0;
61 sh4r.pc = sh4r.pr;
62 }
64 code = xlat_get_code_by_vma( sh4r.pc );
65 if( code == NULL ) {
66 code = sh4_translate_basic_block( sh4r.pc );
67 }
68 }
69 last_pc = sh4r.pc;
70 last_code = code;
71 code = code();
72 }
74 if( sh4r.sh4_state != SH4_STATE_STANDBY ) {
75 TMU_run_slice( nanosecs );
76 SCIF_run_slice( nanosecs );
77 }
78 return nanosecs;
79 }
81 uint8_t *xlat_output;
83 /**
84 * Translate a linear basic block, ie all instructions from the start address
85 * (inclusive) until the next branch/jump instruction or the end of the page
86 * is reached.
87 * @return the address of the translated block
88 * eg due to lack of buffer space.
89 */
90 void * sh4_translate_basic_block( sh4addr_t start )
91 {
92 sh4addr_t pc = start;
93 sh4addr_t lastpc = (pc&0xFFFFF000)+0x1000;
94 int done;
95 xlat_cache_block_t block = xlat_start_block( start );
96 xlat_output = (uint8_t *)block->code;
97 uint8_t *eob = xlat_output + block->size;
98 sh4_translate_begin_block(pc);
100 do {
101 if( eob - xlat_output < MAX_INSTRUCTION_SIZE ) {
102 uint8_t *oldstart = block->code;
103 block = xlat_extend_block( xlat_output - oldstart + MAX_INSTRUCTION_SIZE );
104 xlat_output = block->code + (xlat_output - oldstart);
105 eob = block->code + block->size;
106 }
107 done = sh4_translate_instruction( pc );
108 assert( xlat_output <= eob );
109 pc += 2;
110 if ( pc >= lastpc ) {
111 done = 2;
112 }
113 } while( !done );
114 pc += (done - 2);
115 if( eob - xlat_output < EPILOGUE_SIZE ) {
116 uint8_t *oldstart = block->code;
117 block = xlat_extend_block( xlat_output - oldstart + EPILOGUE_SIZE );
118 xlat_output = block->code + (xlat_output - oldstart);
119 }
120 sh4_translate_end_block(pc);
121 xlat_commit_block( xlat_output - block->code, pc-start );
122 return block->code;
123 }
125 /**
126 * Translate a linear basic block to a temporary buffer, execute it, and return
127 * the result of the execution. The translation is discarded.
128 */
129 void *sh4_translate_and_run( sh4addr_t start )
130 {
131 unsigned char buf[65536];
133 sh4addr_t pc = start;
134 int done;
135 xlat_output = buf;
136 uint8_t *eob = xlat_output + sizeof(buf);
138 sh4_translate_begin_block(pc);
140 while( (done = sh4_translate_instruction( pc )) == 0 ) {
141 assert( (eob - xlat_output) >= MAX_INSTRUCTION_SIZE );
142 pc += 2;
143 }
144 pc+=2;
145 sh4_translate_end_block(pc);
147 void * (*code)() = (void *)buf;
148 return code();
149 }
.