Welcome! Log In Create A New Profile

Advanced

Code dump on my dol loader app

Posted by Cypri 
Code dump on my dol loader app
August 16, 2010 07:53PM
Okay, so I am trying to write a very simple .dol loader that loads my other app pngmove (pngmove runs fine when loaded on hbc) and I am getting a code dump. I don't know how to read code dumps so maybe someone can look at the source and figure out why this is happening, cause I've been looking at this code for about an hour and see nothing wrong. (It is modified from loadmii)

// normal includes
#include 
#include 
#include 
#include  
#include 
#include 
 
// SDL includes
#include 
#include 
#include 
#include 

#define maxTextSections 7
#define maxDataSections 11

u32 relocateDol (u8 *buffer);
 
// screen surface, the place where everything will get print onto
SDL_Surface *screen = NULL;
SDL_Surface *player = NULL;

int playerX = 50;
int playerY = 50;

SDL_RWops *rwop;

FILE * errorlog;

typedef struct _dolheader 
{
	u32 textoff [maxTextSections];
	u32 dataoff [maxDataSections];
	u32 textmem [maxTextSections];
	u32 datamem [maxDataSections];
	u32 textsize[maxTextSections];
	u32 datasize[maxDataSections];
	u32 bssmem;
	u32 bsssize;
	u32 entry;
} dolheader;
 
void init(){
 
    // initialize SDL video. If there was an error SDL shows it on the screen
    if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 )
    {
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError() );
		SDL_Delay( 5000 );
        exit(EXIT_FAILURE);
    }
 
    // button initialization
    WPAD_Init();
 
    // make sure SDL cleans up before exit
    atexit(SDL_Quit);
    SDL_ShowCursor(SDL_DISABLE);
 
    // create a new window
    screen = SDL_SetVideoMode(640, 480, 16, SDL_DOUBLEBUF);
    if ( !screen )
    {
        fprintf(stderr, "Unable to set video: %s\n", SDL_GetError());
		SDL_Delay( 5000 );
        exit(EXIT_FAILURE);
    }
}
 
// this will be used in further lessons, not in lesson 1
void apply_surface ( int x, int y, SDL_Surface* source, SDL_Surface* destination ){
 
     // make a temporary rectangle to hold the offsets
     SDL_Rect offset;
 
     // give the offsets to the rectangle
     offset.x = x;
     offset.y = y;
 
     // blit the surface
     SDL_BlitSurface( source, NULL, destination, &offset );
}
 
void cleanup(){
 
     // we have to quit SDL
     SDL_Quit();
     exit(EXIT_SUCCESS);
}

u32 relocateDol (u8 *buffer)
{
        int loop;
        dolheader *hdr = (dolheader *)buffer;
        memset((void *)hdr->bssmem, 0, hdr->bsssize);
		printf("BSS @ %08x (%08x)\n", hdr->bssmem, hdr->bsssize);
        for (loop = 0; loop < maxTextSections; loop++)
        {
			if (hdr->textsize[loop])
			{	
				printf("Text @ %08x (%08x)\n", hdr->textmem[loop], hdr->textsize[loop]);
                memcpy((void *)hdr->textmem[loop], buffer + hdr->textoff[loop], hdr->textsize[loop]);
				DCFlushRange((void *)hdr->textmem[loop], hdr->textsize[loop]);
				ICInvalidateRange((void *)hdr->textmem[loop], hdr->textsize[loop]);
			}
        }
        for (loop = 0; loop < maxDataSections; loop++)
        {
			if (hdr->datasize[loop])
			{
				printf("Data @ %08x (%08x)\n", hdr->datamem[loop], hdr->datasize[loop]);
                memcpy((void *)hdr->datamem[loop], buffer + hdr->dataoff[loop], hdr->datasize[loop]);
				DCFlushRange((void *)hdr->datamem[loop], hdr->datasize[loop]);
			}
        }
		printf("entry %08x\n", hdr->entry);
        return hdr->entry;
}  

 
int main(int argc, char** argv){
	// main function. Always starts first
 
	// to stop the while loop
	bool done = false;
 
	// start init() function
	init();
	
	fatInitDefault();
	
	
	u8 *bufPtr = (u8) 0x92000000;

	int size_of_file;
	FILE *fp = fopen("sd:/apps/pngmove/boot.dol","rb");
	fseek(fp, 0, SEEK_END); 
	size_of_file = ftell(fp);
	fseek(fp, 0, SEEK_SET); 
	fread(bufPtr,1,size_of_file,fp);
	typedef void (*Entry)();
	Entry entry = reinterpret_cast (relocateDol(bufPtr)); 
	IOS_ReloadIOS(36);
	//Do clean up stuff, like deallocating memory
	entry();
	
	// start cleanup() function
	cleanup();
 
    return 0;
}
Re: Code dump on my dol loader app
August 17, 2010 03:25AM
It's probably this line in main: IOS_ReloadIOS(36);

Try changing it to a different IOS (like 58) or having it reload the IOS that was loaded when the app began.



Edited 1 time(s). Last edit at 08/17/2010 03:25AM by Arikado.
Re: Code dump on my dol loader app
August 17, 2010 03:43AM
Thanks, but the problem was that my buffer pointer was empty.
Sorry, only registered users may post in this forum.

Click here to login