filename | src/sh4/sh4trans.c |
changeset | 430:467519b050f4 |
prev | 417:bd927df302a9 |
next | 527:14c9489f647e |
author | nkeynes |
date | Wed Oct 31 09:10:23 2007 +0000 (16 years ago) |
permissions | -rw-r--r-- |
last change | Add save/restore of render buffers in save states Gzip memory blocks in save states Move front-buffer management back to pvr2 Add screenshot preview when loading save states Various minor fixes and cleanups |
view | annotate | diff | log | raw |
1 /**
2 * $Id: sh4trans.c,v 1.8 2007-10-08 12:06:01 nkeynes Exp $
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"
26 /**
27 * Execute a timeslice using translated code only (ie translate/execute loop)
28 * Note this version does not support breakpoints
29 */
30 uint32_t sh4_xlat_run_slice( uint32_t nanosecs )
31 {
32 sh4r.slice_cycle = 0;
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;
38 }
39 }
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 ) {
45 event_execute();
46 }
47 /* Eventq execute may (quite likely) deliver an immediate IRQ */
48 if( sh4r.event_types & PENDING_IRQ ) {
49 sh4_accept_interrupt();
50 code = NULL;
51 }
52 }
54 if( code == NULL ) {
55 if( sh4r.pc > 0xFFFFFF00 ) {
56 syscall_invoke( sh4r.pc );
57 sh4r.in_delay_slot = 0;
58 sh4r.pc = sh4r.pr;
59 }
61 code = xlat_get_code(sh4r.pc);
62 if( code == NULL ) {
63 code = sh4_translate_basic_block( sh4r.pc );
64 }
65 }
66 code = code();
67 }
69 if( sh4r.sh4_state != SH4_STATE_STANDBY ) {
70 TMU_run_slice( nanosecs );
71 SCIF_run_slice( nanosecs );
72 }
73 return nanosecs;
74 }
76 uint8_t *xlat_output;
78 /**
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
81 * is reached.
82 * @return the address of the translated block
83 * eg due to lack of buffer space.
84 */
85 void * sh4_translate_basic_block( sh4addr_t start )
86 {
87 sh4addr_t pc = start;
88 sh4addr_t lastpc = (pc&0xFFFFF000)+0x1000;
89 int done;
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);
95 do {
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;
101 }
102 done = sh4_x86_translate_instruction( pc );
103 assert( xlat_output <= eob );
104 pc += 2;
105 if ( pc >= lastpc ) {
106 done = 2;
107 }
108 } while( !done );
109 pc += (done - 2);
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);
114 }
115 sh4_translate_end_block(pc);
116 xlat_commit_block( xlat_output - block->code, pc-start );
117 return block->code;
118 }
120 /**
121 * Translate a linear basic block to a temporary buffer, execute it, and return
122 * the result of the execution. The translation is discarded.
123 */
124 void *sh4_translate_and_run( sh4addr_t start )
125 {
126 unsigned char buf[65536];
128 sh4addr_t pc = start;
129 int done;
130 xlat_output = buf;
131 uint8_t *eob = xlat_output + sizeof(buf);
133 sh4_translate_begin_block(pc);
135 while( (done = sh4_x86_translate_instruction( pc )) == 0 ) {
136 assert( (eob - xlat_output) >= MAX_INSTRUCTION_SIZE );
137 pc += 2;
138 }
139 pc+=2;
140 sh4_translate_end_block(pc);
142 void * (*code)() = (void *)buf;
143 return code();
144 }
.