把fit_size的策略再改回去

This commit is contained in:
anod 2023-03-17 17:43:00 +08:00
parent 23a7f4dfd7
commit f830537f9e

View File

@ -337,11 +337,13 @@ static CodeLocation rom_fit_newsize( CodeLocation rom, int realend, int totalsiz
{ {
u32 size = realend + totalsize; u32 size = realend + totalsize;
if( size > SIZE_32M )
{
// get the biggest space that all bytes is 0 // get the biggest space that all bytes is 0
CodeLocation found=NULL, current=NULL; CodeLocation found=NULL, current=NULL;
int szfound=0, szcurrent=0; int szfound=0, szcurrent=0;
int reallen = INSTR_LEN( realend ); int reallen = INSTR_LEN( realend );
instruction_t freeinstr = 0; // 0/0xffffffff will be free instruction_t freeinstr = 0; // 0/0xffffffff will be free
#define START_FREE_BLOCK(n) {\ #define START_FREE_BLOCK(n) {\
current = rom+i;\ current = rom+i;\
@ -357,46 +359,46 @@ static CodeLocation rom_fit_newsize( CodeLocation rom, int realend, int totalsiz
szcurrent = 0;\ szcurrent = 0;\
} }
for( int i=0; i < reallen; ++i ) for( int i=0; i < reallen; ++i )
{
if( rom[i] == 0 )
{ {
if( szcurrent == 0 ) if( rom[i] == 0 )
{ {
START_FREE_BLOCK(0); if( szcurrent == 0 )
{
START_FREE_BLOCK(0);
}
else
{
if( freeinstr == 0 )// same block
szcurrent += INSTR_SIZE;
else END_FREE_BLOCK;
}
} }
else else if( rom[i] == 0xffffffff )
{ {
if( freeinstr == 0 )// same block if( szcurrent == 0xffffffff )
szcurrent += INSTR_SIZE; {
else END_FREE_BLOCK; START_FREE_BLOCK(0xffffffff);
}
else
{
if( freeinstr == 0xffffffff )
szcurrent += INSTR_SIZE;
else END_FREE_BLOCK;
}
} }
else if( szcurrent > 0 ) END_FREE_BLOCK;
} }
else if( rom[i] == 0xffffffff )
// the zero-filled space is big enough, 3 is a guess value
if( szfound > totalsize * 3 )
{ {
if( szcurrent == 0xffffffff ) return found + FIT_SPACE_RESERVED;
{
START_FREE_BLOCK(0xffffffff);
}
else
{
if( freeinstr == 0xffffffff )
szcurrent += INSTR_SIZE;
else END_FREE_BLOCK;
}
} }
else if( szcurrent > 0 ) END_FREE_BLOCK; // cannot find a good block
else return NULL;
} }
// the zero-filled space is big enough, 3 is a guess value
if( szfound > totalsize * 3 )
{
return found + FIT_SPACE_RESERVED;
}
// cannot find a good block
if( size > SIZE_32M ) return NULL;
// grow cart volumn // grow cart volumn
else if( szrom < size || nextPow2(size) != nextPow2(szrom) ) else if( szrom < size || nextPow2(size) != nextPow2(szrom) )
*newsize = size + INSTR_SIZE; *newsize = size + INSTR_SIZE;