Search
lxdream.org :: lxdream :: r410:5f8413358e7f
lxdream 0.9.1
released Jun 29
Download Now
changeset410:5f8413358e7f
parent409:549e00835448
child411:5ae249d63c44
authornkeynes
dateSat Sep 29 11:06:40 2007 +0000 (16 years ago)
Change extend-block to take a requested size
Terminate blocks on page boundaries for easier invalidation
src/sh4/sh4trans.c
src/sh4/sh4trans.h
src/sh4/xltcache.c
src/sh4/xltcache.h
1.1 --- a/src/sh4/sh4trans.c Sat Sep 29 05:33:02 2007 +0000
1.2 +++ b/src/sh4/sh4trans.c Sat Sep 29 11:06:40 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: sh4trans.c,v 1.5 2007-09-28 07:27:20 nkeynes Exp $
1.6 + * $Id: sh4trans.c,v 1.6 2007-09-29 11:06:40 nkeynes Exp $
1.7 *
1.8 * SH4 translation core module. This part handles the non-target-specific
1.9 * section of the translation.
1.10 @@ -86,6 +86,7 @@
1.11 void * sh4_translate_basic_block( sh4addr_t start )
1.12 {
1.13 sh4addr_t pc = start;
1.14 + sh4addr_t lastpc = (pc&0xFFFFF000)+0x1000;
1.15 int done;
1.16 xlat_cache_block_t block = xlat_start_block( start );
1.17 xlat_output = (uint8_t *)block->code;
1.18 @@ -95,14 +96,23 @@
1.19 do {
1.20 if( eob - xlat_output < MAX_INSTRUCTION_SIZE ) {
1.21 uint8_t *oldstart = block->code;
1.22 - block = xlat_extend_block();
1.23 + block = xlat_extend_block( xlat_output - oldstart + MAX_INSTRUCTION_SIZE );
1.24 xlat_output = block->code + (xlat_output - oldstart);
1.25 eob = block->code + block->size;
1.26 }
1.27 done = sh4_x86_translate_instruction( pc );
1.28 + assert( xlat_output <= eob );
1.29 pc += 2;
1.30 + if ( pc >= lastpc ) {
1.31 + done = 2;
1.32 + }
1.33 } while( !done );
1.34 pc += (done - 2);
1.35 + if( eob - xlat_output < EPILOGUE_SIZE ) {
1.36 + uint8_t *oldstart = block->code;
1.37 + block = xlat_extend_block( xlat_output - oldstart + EPILOGUE_SIZE );
1.38 + xlat_output = block->code + (xlat_output - oldstart);
1.39 + }
1.40 sh4_translate_end_block(pc);
1.41 xlat_commit_block( xlat_output - block->code, pc-start );
1.42 return block->code;
2.1 --- a/src/sh4/sh4trans.h Sat Sep 29 05:33:02 2007 +0000
2.2 +++ b/src/sh4/sh4trans.h Sat Sep 29 11:06:40 2007 +0000
2.3 @@ -1,5 +1,5 @@
2.4 /**
2.5 - * $Id: sh4trans.h,v 1.3 2007-09-28 07:27:20 nkeynes Exp $
2.6 + * $Id: sh4trans.h,v 1.4 2007-09-29 11:06:40 nkeynes Exp $
2.7 *
2.8 * SH4->x86 translation module
2.9 *
2.10 @@ -23,7 +23,10 @@
2.11 * writing the entire epilogue
2.12 */
2.13 #define MAX_INSTRUCTION_SIZE 256
2.14 -
2.15 +/** Maximum size of the translation epilogue (current real size is 116 bytes, so
2.16 + * allows a little room
2.17 + */
2.18 +#define EPILOGUE_SIZE 128
2.19 /**
2.20
2.21 */
3.1 --- a/src/sh4/xltcache.c Sat Sep 29 05:33:02 2007 +0000
3.2 +++ b/src/sh4/xltcache.c Sat Sep 29 11:06:40 2007 +0000
3.3 @@ -1,5 +1,5 @@
3.4 /**
3.5 - * $Id: xltcache.c,v 1.6 2007-09-28 07:26:35 nkeynes Exp $
3.6 + * $Id: xltcache.c,v 1.7 2007-09-29 11:06:40 nkeynes Exp $
3.7 *
3.8 * Translation cache management. This part is architecture independent.
3.9 *
3.10 @@ -53,7 +53,6 @@
3.11 xlat_cache_block_t xlat_old_cache;
3.12 xlat_cache_block_t xlat_old_cache_ptr;
3.13 static void ***xlat_lut;
3.14 -static void **xlat_lut2; /* second-tier page info */
3.15 static gboolean xlat_initialized = FALSE;
3.16
3.17 void xlat_cache_init()
3.18 @@ -197,10 +196,10 @@
3.19
3.20 void *xlat_get_code( sh4addr_t address )
3.21 {
3.22 - void *result;
3.23 + void *result = NULL;
3.24 void **page = xlat_lut[XLAT_LUT_PAGE(address)];
3.25 if( page != NULL ) {
3.26 - result = (void *)(((uint32_t)page[XLAT_LUT_ENTRY(address)]) & 0xFFFFFFFC);
3.27 + result = (void *)(((uint32_t)(page[XLAT_LUT_ENTRY(address)])) & 0xFFFFFFFC);
3.28 }
3.29 return result;
3.30 }
3.31 @@ -237,6 +236,7 @@
3.32 static inline xlat_cache_block_t xlat_cut_block( xlat_cache_block_t block, int cutsize )
3.33 {
3.34 cutsize = (cutsize + 3) & 0xFFFFFFFC; // force word alignment
3.35 + assert( cutsize <= block->size );
3.36 if( block->size > cutsize + MIN_TOTAL_SIZE ) {
3.37 int oldsize = block->size;
3.38 block->size = cutsize;
3.39 @@ -365,36 +365,38 @@
3.40 return xlat_new_create_ptr;
3.41 }
3.42
3.43 -xlat_cache_block_t xlat_extend_block()
3.44 +xlat_cache_block_t xlat_extend_block( uint32_t newSize )
3.45 {
3.46 - if( xlat_new_cache_ptr->size == 0 ) {
3.47 - /* Migrate to the front of the cache to keep it contiguous */
3.48 - xlat_new_create_ptr->active = 0;
3.49 - char *olddata = xlat_new_create_ptr->code;
3.50 - int oldsize = xlat_new_create_ptr->size;
3.51 - int size = oldsize + MIN_BLOCK_SIZE; /* minimum expansion */
3.52 - void **lut_entry = xlat_new_create_ptr->lut_entry;
3.53 - int allocation = -sizeof(struct xlat_cache_block);
3.54 - xlat_new_cache_ptr = xlat_new_cache;
3.55 - do {
3.56 + while( xlat_new_create_ptr->size < newSize ) {
3.57 + if( xlat_new_cache_ptr->size == 0 ) {
3.58 + /* Migrate to the front of the cache to keep it contiguous */
3.59 + xlat_new_create_ptr->active = 0;
3.60 + char *olddata = xlat_new_create_ptr->code;
3.61 + int oldsize = xlat_new_create_ptr->size;
3.62 + int size = oldsize + MIN_BLOCK_SIZE; /* minimum expansion */
3.63 + void **lut_entry = xlat_new_create_ptr->lut_entry;
3.64 + int allocation = -sizeof(struct xlat_cache_block);
3.65 + xlat_new_cache_ptr = xlat_new_cache;
3.66 + do {
3.67 + if( xlat_new_cache_ptr->active ) {
3.68 + xlat_promote_to_temp_space( xlat_new_cache_ptr );
3.69 + }
3.70 + allocation += xlat_new_cache_ptr->size + sizeof(struct xlat_cache_block);
3.71 + xlat_new_cache_ptr = NEXT(xlat_new_cache_ptr);
3.72 + } while( allocation < size );
3.73 + xlat_new_create_ptr = xlat_new_cache;
3.74 + xlat_new_create_ptr->active = 1;
3.75 + xlat_new_create_ptr->size = allocation;
3.76 + xlat_new_create_ptr->lut_entry = lut_entry;
3.77 + *lut_entry = &xlat_new_create_ptr->code;
3.78 + memmove( xlat_new_create_ptr->code, olddata, oldsize );
3.79 + } else {
3.80 if( xlat_new_cache_ptr->active ) {
3.81 xlat_promote_to_temp_space( xlat_new_cache_ptr );
3.82 }
3.83 - allocation += xlat_new_cache_ptr->size + sizeof(struct xlat_cache_block);
3.84 + xlat_new_create_ptr->size += xlat_new_cache_ptr->size + sizeof(struct xlat_cache_block);
3.85 xlat_new_cache_ptr = NEXT(xlat_new_cache_ptr);
3.86 - } while( allocation < size );
3.87 - xlat_new_create_ptr = xlat_new_cache;
3.88 - xlat_new_create_ptr->active = 1;
3.89 - xlat_new_create_ptr->size = allocation;
3.90 - xlat_new_create_ptr->lut_entry = lut_entry;
3.91 - *lut_entry = &xlat_new_create_ptr->code;
3.92 - memmove( xlat_new_create_ptr->code, olddata, oldsize );
3.93 - } else {
3.94 - if( xlat_new_cache_ptr->active ) {
3.95 - xlat_promote_to_temp_space( xlat_new_cache_ptr );
3.96 }
3.97 - xlat_new_create_ptr->size += xlat_new_cache_ptr->size + sizeof(struct xlat_cache_block);
3.98 - xlat_new_cache_ptr = NEXT(xlat_new_cache_ptr);
3.99 }
3.100 return xlat_new_create_ptr;
3.101
4.1 --- a/src/sh4/xltcache.h Sat Sep 29 05:33:02 2007 +0000
4.2 +++ b/src/sh4/xltcache.h Sat Sep 29 11:06:40 2007 +0000
4.3 @@ -1,5 +1,5 @@
4.4 /**
4.5 - * $Id: xltcache.h,v 1.5 2007-09-28 07:26:35 nkeynes Exp $
4.6 + * $Id: xltcache.h,v 1.6 2007-09-29 11:06:40 nkeynes Exp $
4.7 *
4.8 * Translation cache support (architecture independent)
4.9 *
4.10 @@ -37,7 +37,7 @@
4.11 * and xlat_commit_block()).
4.12 * @return the new block, which may be different from the old block.
4.13 */
4.14 -xlat_cache_block_t xlat_extend_block();
4.15 +xlat_cache_block_t xlat_extend_block( uint32_t newSize );
4.16
4.17 /**
4.18 * Commit the current translation block
.