zero-terminate relocation list

This commit is contained in:
Wolfgang Thaller 2017-09-23 20:11:38 +02:00
parent 5059b87fe4
commit 57906f91c1
2 changed files with 11 additions and 7 deletions

View File

@ -170,6 +170,7 @@ void ElfToFlt(string input, string output)
byte(out, 0x00); byte(out, 0x00);
for(int reloc : relocs) for(int reloc : relocs)
longword(out, reloc); longword(out, reloc);
longword(out, -1); // not part of the FLT specification: terminate reloc list
} }
string argvZero; string argvZero;

View File

@ -99,7 +99,7 @@ static Retro68RelocState relocState __attribute__ ((nocommon, section(".text")))
} while(0) } while(0)
#endif #endif
#if 0 #if 1
#define log(x) do { } while(0) #define log(x) do { } while(0)
#else #else
#define log(x) do { \ #define log(x) do { \
@ -230,17 +230,16 @@ void Retro68Relocate()
long n = header->reloc_count; long n = header->reloc_count;
long *relocs = (long*)( (char*)header + header->reloc_start );
long i;
uint32_t text_and_data_size = orig_edata - orig_stext; uint32_t text_and_data_size = orig_edata - orig_stext;
uint32_t total_size = orig_ebss - orig_stext; // FIXME: not true for repeated reloc uint32_t total_size = orig_ebss - orig_stext; // FIXME: not true for repeated reloc
long bss_displacement = 0;
assert(text_and_data_size == header->data_end - sizeof(*header)); assert(text_and_data_size == header->data_end - sizeof(*header));
assert((uint8_t*)relocs == base + text_and_data_size);
assert(total_size == header->bss_end - sizeof(*header)); assert(total_size == header->bss_end - sizeof(*header));
long bss_displacement = 0;
// Allocate BSS section (uninitialized/zero-initialized global data) // Allocate BSS section (uninitialized/zero-initialized global data)
if(!rState->bssPtr) if(!rState->bssPtr)
{ {
@ -252,11 +251,15 @@ void Retro68Relocate()
bss_displacement = (uint8_t*)rState->bssPtr - &_sbss; bss_displacement = (uint8_t*)rState->bssPtr - &_sbss;
} }
long i;
// Process relocation records // Process relocation records
for(i = 0; i < n; i++)
for(long *reloc = (long*)( base + text_and_data_size );
*reloc != -1;
++reloc)
{ {
//Debugger(); //Debugger();
uint8_t *addrPtr = base + relocs[i]; uint8_t *addrPtr = base + *reloc;
uint32_t addr; uint32_t addr;
/*log(relocs + i); /*log(relocs + i);