mirror of
https://gitee.com/anod/open_agb_firm.git
synced 2025-05-08 06:44:12 +08:00
修正非标准尺寸rom扩容的bug
This commit is contained in:
parent
0f21bb6094
commit
77ab4b2309
@ -336,44 +336,71 @@ static int cht_calc_needsize( int mode, int numirq )
|
|||||||
static CodeLocation rom_fit_newsize( CodeLocation rom, int realend, int totalsize, u32 szrom, u32 *newsize )
|
static CodeLocation rom_fit_newsize( CodeLocation rom, int realend, int totalsize, u32 szrom, u32 *newsize )
|
||||||
{
|
{
|
||||||
u32 size = realend + totalsize;
|
u32 size = realend + totalsize;
|
||||||
if( size > SIZE_32M )
|
|
||||||
|
// get the biggest space that all bytes is 0
|
||||||
|
CodeLocation found=NULL, current=NULL;
|
||||||
|
int szfound=0, szcurrent=0;
|
||||||
|
int reallen = INSTR_LEN( realend );
|
||||||
|
instruction_t freeinstr = 0; // 0/0xffffffff will be free
|
||||||
|
|
||||||
|
#define START_FREE_BLOCK(n) {\
|
||||||
|
current = rom+i;\
|
||||||
|
freeinstr = n;\
|
||||||
|
}
|
||||||
|
#define END_FREE_BLOCK {\
|
||||||
|
if( szcurrent > szfound )\
|
||||||
|
{\
|
||||||
|
found = current;\
|
||||||
|
szfound = szcurrent;\
|
||||||
|
}\
|
||||||
|
current = NULL;\
|
||||||
|
szcurrent = 0;\
|
||||||
|
}
|
||||||
|
|
||||||
|
for( int i=0; i < reallen; ++i )
|
||||||
{
|
{
|
||||||
// get the biggest space that all bytes is 0
|
if( rom[i] == 0 )
|
||||||
CodeLocation found=NULL, current=NULL;
|
|
||||||
int szfound=0, szcurrent=0;
|
|
||||||
int reallen = INSTR_LEN( realend );
|
|
||||||
for( int i=0; i < reallen; ++i )
|
|
||||||
{
|
{
|
||||||
if( rom[i] == 0 )
|
if( szcurrent == 0 )
|
||||||
{
|
{
|
||||||
if( szcurrent == 0 ) current = rom+i;
|
START_FREE_BLOCK(0);
|
||||||
szcurrent += INSTR_SIZE;
|
|
||||||
}
|
}
|
||||||
else if( szcurrent > 0 )
|
else
|
||||||
{
|
{
|
||||||
if( szcurrent > szfound )
|
if( freeinstr == 0 )// same block
|
||||||
{
|
szcurrent += INSTR_SIZE;
|
||||||
found = current;
|
else END_FREE_BLOCK;
|
||||||
szfound = szcurrent;
|
}
|
||||||
}
|
}
|
||||||
current = NULL;
|
else if( rom[i] == 0xffffffff )
|
||||||
szcurrent = 0;
|
{
|
||||||
|
if( szcurrent == 0xffffffff )
|
||||||
|
{
|
||||||
|
START_FREE_BLOCK(0xffffffff);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( freeinstr == 0xffffffff )
|
||||||
|
szcurrent += INSTR_SIZE;
|
||||||
|
else END_FREE_BLOCK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// the zero-filled space is big enough, 3 is a guess value
|
else if( szcurrent > 0 ) END_FREE_BLOCK;
|
||||||
if( szfound > totalsize * 3 )
|
|
||||||
{
|
|
||||||
return found + FIT_SPACE_RESERVED;
|
|
||||||
}
|
|
||||||
else return NULL;
|
|
||||||
}
|
}
|
||||||
else if( nextPow2(size) != nextPow2(szrom) )
|
|
||||||
|
// the zero-filled space is big enough, 3 is a guess value
|
||||||
|
if( szfound > totalsize * 3 )
|
||||||
{
|
{
|
||||||
// 似乎没什么要动的
|
return found + FIT_SPACE_RESERVED;
|
||||||
*newsize = size + INSTR_SIZE; // reserve a word for padding
|
|
||||||
return rom + INSTR_LEN( realend );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cannot find a good block
|
||||||
|
if( size > SIZE_32M ) return NULL;
|
||||||
|
|
||||||
|
// grow cart volumn
|
||||||
|
else if( szrom < size || nextPow2(size) != nextPow2(szrom) )
|
||||||
|
*newsize = size + INSTR_SIZE;
|
||||||
|
|
||||||
return rom + INSTR_LEN( realend );
|
return rom + INSTR_LEN( realend );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user