Knight0fDragon
Patron Supporter
Does anybody have an idea on how thunk functions are done for the overlay/library files in most Saturn games? Specifically, is there a way to reproduce them in GCC.
Basically, each overlay has a header section that consists of 12 bytes per thunk function, and in those 12 bytes is code to retrieve the address of the function you really want to call, then jump to that address.
This allows you to put your library function calls at the very beginning so that if you need to update your overlay code, you do not need to recompile your entire game.
The assembly behind it looks like this:
Currently I am doing something like this:
but it seems it should be possible to generate something for myself to avoid having to do this.
Any help on the matter is appreciated.
Basically, each overlay has a header section that consists of 12 bytes per thunk function, and in those 12 bytes is code to retrieve the address of the function you really want to call, then jump to that address.
This allows you to put your library function calls at the very beginning so that if you need to update your overlay code, you do not need to recompile your entire game.
The assembly behind it looks like this:
Code:
mov.l @address,r0
jmp @r0
nop
nop
@address:0x060#####.
C:
#pragma GCC push_options
#pragma GCC optimize ("O0")
extern void __SEC_1_START __asm("_SEC_1_START");
extern int __SEC_2_START __asm("_SEC_2_START");
typedef struct
{
unsigned int movl_jmp;
unsigned int nop_nop;
unsigned int address;
} Thunk;
#define ThunkFunction(addr) { 0xd001402b,0x00090009,((unsigned int)addr)}
#define ThunkData(addr) { ((unsigned int)(addr)),0x0,0x0}
static __attribute__((section (".0_thunk"))) Thunk Header[] =
{
ThunkFunction(&__SEC_1_START),
ThunkData(&__SEC_2_START)
};
#pragma GCC pop_options
Any help on the matter is appreciated.