All pastes #404084 Raw Edit

Someone

public text v1 · immutable
·published 2007-03-20 20:23 UTC
rendered paste body
void load_dol(void *dol, int size)
{
		void (*entrypoint)();
		char nfo[50];
	if ((*(unsigned long*)dol) > 0x1000)
	{   write_font(500,500,"loading binary file...");
		memcpy((void*)0x80003100, dol, size);
		entrypoint = (void(*)())0x80003100;
	} else
	{
		struct dol_s
		{
			unsigned long sec_pos[18];
			unsigned long sec_address[18];
			unsigned long sec_size[18];
			unsigned long bss_address, bss_size, entry_point;
		} *d = (struct dol_s*)dol;
		int i;
		
		for (i=0; i<18; ++i)
		{
			if (!d->sec_size[i])
				continue;
				
			sprintf(nfo,"Relocating %08lx to %08lx (%ld bytes)", d->sec_pos[i], d->sec_address[i], d->sec_size[i]);
			write_font(100,100,nfo);
			memcpy((void*)d->sec_address[i], ((unsigned char*)dol)+d->sec_pos[i], d->sec_size[i]);
		}
		
		sprintf(nfo, "Clearing BSS (at %08lx, %lu bytes...)", d->bss_address, d->bss_size);
		write_font(100,124,nfo);
        memset((void*)d->bss_address, 0, d->bss_size);
		entrypoint = (void(*)())d->entry_point;
}
	mtmsr((mfmsr() | 2) & ~0x8000);
	sprintf(nfo, "Jumping to %p", entrypoint);
	write_font(100,148,nfo);
	flush_code(0x80000000, 0x1800000);
	exception_close();
	entrypoint();
	write_font(100,172,"returned from entrypoint - should never happen. but happens.");
	while(1);
}