|
my dol loader just hangs... August 17, 2010 03:45AM | Registered: 15 years ago Posts: 29 |
// normal includes #include#include #include #include #include #include #include #include #include #include #include #include #include #include #include // SDL includes #include #include #include #include #define maxTextSections 7 #define maxDataSections 11 u32 relocateDol (u8 *buffer); 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; static void *xfb = NULL; static GXRModeObj *rmode = NULL; u32 relocateDol (u8 *buffer) { printf("int loop;\n"); int loop; printf("int loop;\n"); dolheader *hdr = (dolheader *)buffer; printf("hdr->bsssize %i\n", hdr->bsssize); memset((void *)hdr->bssmem, 0, hdr->bsssize); //stops here printf("BSS @ %08x (%08x)\n", hdr->bssmem, hdr->bsssize); sleep(3); 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; } void cleanup () { /* Unmount the FAT device... */ fatUnmount("sd"); /* and send the shutdown command. */ __io_wiisd.startup(); __io_usbstorage.shutdown(); __io_wiidvd.shutdown(); __io_gcsda.shutdown(); __io_gcsdb.shutdown(); /* We dont need WPAD anymore */ WPAD_Shutdown(); /* Reload an ios */ //reloadIOS(); /* Then g'bye libOGC. */ SYS_ResetSystem(SYS_SHUTDOWN, 0, 0); /* Disable exceptions */ // __exception_closeall(); } int validateHeader(u8 *buffer) { if (buffer[0] == 0x0 && buffer[1] == 0x0 && buffer[2] == 0x1) { return 1337; } return 0; } int main(int argc, char** argv){ // main function. Always starts first // Initialise the video system VIDEO_Init(); // This function initialises the attached controllers WPAD_Init(); // Obtain the preferred video mode from the system // This will correspond to the settings in the Wii menu rmode = VIDEO_GetPreferredMode(NULL); // Allocate memory for the display in the uncached region xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); // Initialise the console, required for printf console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); // Set up the video registers with the chosen mode VIDEO_Configure(rmode); // Tell the video hardware where our display memory is VIDEO_SetNextFramebuffer(xfb); // Make the display visible VIDEO_SetBlack(FALSE); // Flush the video register changes to the hardware VIDEO_Flush(); // Wait for Video setup to complete VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); printf("\x1b[2;0H"); printf("start\n"); sleep(1); fatInitDefault(); u8 *bufPtr = (u8 *) 0x92000000; int size_of_file; printf("open dol\n"); sleep(1); int filedes = open("sd:/apps/pngmove/boot.dol",O_RDWR); if(filedes < 0){ printf("null dol\n"); sleep(1); return 0; } printf("get size\n"); sleep(1); size_of_file = lseek(filedes, 0, SEEK_END); lseek(filedes, 0, SEEK_SET); printf("read bufptr %i\n", size_of_file); sleep(3); read(filedes, bufPtr, size_of_file); close(filedes); printf("valid? %i\n", validateHeader(bufPtr)); printf("typedef void (*Entry)()\n"); sleep(1); void (*entry)(); printf("entry = (void (*)())relocateDol(bufPtr);\n"); sleep(1); entry = (void (*)())relocateDol(bufPtr); printf("IOS_ReloadIOS(36);\n"); sleep(1); IOS_ReloadIOS(36); //Do clean up stuff, like deallocating memory /* Set CPU/BUS clock as Nintendo SDK apps require so. */ *(vu32*)0x800000F8 = 0x0E7BE2C0; *(vu32*)0x800000FC = 0x2B73A840; __lwp_thread_stopmultitasking(entry); printf("entry();\n"); sleep(1); entry(); return 0; }
|
Re: my dol loader just hangs... August 17, 2010 07:55AM | Moderator Registered: 17 years ago Posts: 703 |
|
Re: my dol loader just hangs... August 17, 2010 09:02AM | Registered: 17 years ago Posts: 276 |
--section-start,.init=0x81200000
u8 *bufPtr = (u8 *) 0x92000000;
u8 *bufPtr = (u8) 0x92000000;
|
Re: my dol loader just hangs... August 17, 2010 08:51PM | Registered: 15 years ago Posts: 29 |
u8 *bufPtr = (u8 *) 0x92000000;and added
--section-start,.init=0x81200000to the make file.
|
Re: my dol loader just hangs... August 17, 2010 11:27PM | Moderator Registered: 17 years ago Posts: 703 |
|
Re: my dol loader just hangs... August 18, 2010 01:19AM | Registered: 15 years ago Posts: 29 |
|
Re: my dol loader just hangs... August 18, 2010 04:41AM | Admin Registered: 17 years ago Posts: 5,132 |
|
Re: my dol loader just hangs... August 18, 2010 07:12AM | Registered: 15 years ago Posts: 29 |
|
Re: my dol loader just hangs... August 18, 2010 09:07AM | Moderator Registered: 17 years ago Posts: 703 |
|
Re: my dol loader just hangs... August 18, 2010 10:03AM | Registered: 17 years ago Posts: 276 |
|
Re: my dol loader just hangs... August 18, 2010 09:32PM | Registered: 15 years ago Posts: 29 |
read(0x92000000, bufPtr, size_of_file);
int validateHeader(u8 *buffer)
{
if (buffer[0] == 0x0 &&
buffer[1] == 0x0 &&
buffer[2] == 0x1)
{
return 1337;
}
return 0;
}
int main(int argc, char** argv){
// main function. Always starts first
// Initialise the video system
VIDEO_Init();
// This function initialises the attached controllers
WPAD_Init();
// Obtain the preferred video mode from the system
// This will correspond to the settings in the Wii menu
rmode = VIDEO_GetPreferredMode(NULL);
// Allocate memory for the display in the uncached region
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
// Initialise the console, required for printf
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
// Set up the video registers with the chosen mode
VIDEO_Configure(rmode);
// Tell the video hardware where our display memory is
VIDEO_SetNextFramebuffer(xfb);
// Make the display visible
VIDEO_SetBlack(FALSE);
// Flush the video register changes to the hardware
VIDEO_Flush();
// Wait for Video setup to complete
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
printf("\x1b[2;0H");
printf("start\n");
sleep(1);
fatInitDefault();
u8 *bufPtr = (u8 *) 0x92000000;
int size_of_file;
printf("open dol\n");
sleep(1);
FILE *fp = fopen("sd:/apps/pngmove/boot.dol","rb");
printf("get size\n");
sleep(1);
fseek(fp, 0, SEEK_END);
size_of_file = ftell(fp);
fseek(fp, 0, SEEK_SET);
printf("read bufptr %i\n", size_of_file);
sleep(3);
read(0x92000000, bufPtr, size_of_file);
printf("valid? %i\n", validateHeader(bufPtr));
printf("typedef void (*Entry)()\n");
sleep(1);
void (*entry)();
printf("entry = (void (*)())relocateDol(bufPtr);\n");
sleep(1);
entry = (void (*)())relocateDol(bufPtr);
printf("IOS_ReloadIOS(36);\n");
sleep(1);
IOS_ReloadIOS(36);
/* Set CPU/BUS clock as Nintendo SDK apps require so. */
*(vu32*)0x800000F8 = 0x0E7BE2C0;
*(vu32*)0x800000FC = 0x2B73A840;
__lwp_thread_stopmultitasking(entry);
printf("entry();\n");
sleep(1);
entry();
return 0;
}
|
Re: my dol loader just hangs... August 19, 2010 10:02AM | Registered: 17 years ago Posts: 276 |
|
Re: my dol loader just hangs... August 20, 2010 07:37AM | Registered: 15 years ago Posts: 29 |
int main(int argc, char** argv){
// main function. Always starts first
// Initialise the video system
VIDEO_Init();
// This function initialises the attached controllers
WPAD_Init();
// Obtain the preferred video mode from the system
// This will correspond to the settings in the Wii menu
rmode = VIDEO_GetPreferredMode(NULL);
// Allocate memory for the display in the uncached region
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
// Initialise the console, required for printf
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
// Set up the video registers with the chosen mode
VIDEO_Configure(rmode);
// Tell the video hardware where our display memory is
VIDEO_SetNextFramebuffer(xfb);
// Make the display visible
VIDEO_SetBlack(FALSE);
// Flush the video register changes to the hardware
VIDEO_Flush();
// Wait for Video setup to complete
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
printf("\x1b[2;0H");
printf("start\n");
sleep(1);
fatInitDefault();
u8 *bufPtr = (u8 *) 0x92000000;
int size_of_file;
printf("open dol\n");
sleep(1);
int filedes = open("sd:/apps/pngmove/boot.dol",O_RDWR);
if(filedes < 0){
printf("null dol\n");
sleep(1);
return 0;
}
printf("get size\n");
sleep(1);
size_of_file = lseek(filedes, 0, SEEK_END);
lseek(filedes, 0, SEEK_SET);
printf("read bufptr %i\n", size_of_file);
sleep(3);
read(filedes, bufPtr, size_of_file);
close(filedes);
printf("valid? %i\n", validateHeader(bufPtr));
printf("typedef void (*Entry)()\n");
sleep(1);
void (*entry)();
printf("entry = (void (*)())relocateDol(bufPtr);\n");
sleep(1);
entry = (void (*)())relocateDol(bufPtr);
printf("IOS_ReloadIOS(36);\n");
sleep(1);
IOS_ReloadIOS(36);
//Do clean up stuff, like deallocating memory
/* Set CPU/BUS clock as Nintendo SDK apps require so. */
*(vu32*)0x800000F8 = 0x0E7BE2C0;
*(vu32*)0x800000FC = 0x2B73A840;
__lwp_thread_stopmultitasking(entry);
printf("entry();\n");
sleep(1);
entry();
return 0;
}
|
Re: my dol loader just hangs... August 20, 2010 09:55AM | Registered: 17 years ago Posts: 276 |
/* Open file */
FILE *fp = fopen("sd:/apps/pngmove/boot.dol", "rb");
if (!fp)
{
printf("null dol\n");
sleep(1);
return 0;
}
/* Read size */
fseek(fp, 0, SEEK_END);
size_of_file = ftell(fp);
fseek(fp, 0, SEEK_SET);
/* Read into buffer (4k blocks) */
int done = 0;
while (filesize > 4096)
{
fread(bufPtr + done, 4096, 1, fp);
done += 4096;
filesize -= 4096;
}
/* Read remaining bytes */
if (filesize)
{
fread(bufPtr + done, filesize, 1, fp);
}
/* Close file */
fclose(fp);Quote
I did a little bit more debugging and figured out that the bsssize variable is about twice the size of the size_of_file variable
|
Re: my dol loader just hangs... August 20, 2010 07:18PM | Registered: 15 years ago Posts: 29 |
BSS Address: 80165F60 BSS Size: 00378680 Entry Point: 80004000 Text Section 0: Offset=00000100 Address=80004000 Size=00125460 Data Section 0: Offset=00125580 Address=80129460 Size=0003CB00
|
Re: my dol loader just hangs... August 20, 2010 08:38PM | Registered: 17 years ago Posts: 276 |
|
Re: my dol loader just hangs... August 20, 2010 08:59PM | Registered: 15 years ago Posts: 29 |
BSS Address: 80065F40 BSS Size: 000BF3A0 Entry Point: 80004000 Text Section 0: Offset=00000100 Address=80004000 Size=00055140 Data Section 0: Offset=00055240 Address=80059140 Size=0000CE00Hmm, they're really close together for their address. And their entry point is the same, but I added
--section-start,.init=0x81200000to my make file for the loader.
|
Re: my dol loader just hangs... August 20, 2010 11:13PM | Registered: 17 years ago Posts: 276 |
|
Re: my dol loader just hangs... August 20, 2010 11:55PM | Registered: 15 years ago Posts: 29 |
// normal includes #include#include #include #include #include #include #include #include #include #include #include #include #include #include #include // SDL includes #include #include #include #include #define maxTextSections 7 #define maxDataSections 11 u32 relocateDol (u8 *buffer); 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; static void *xfb = NULL; static GXRModeObj *rmode = NULL; u32 relocateDol (u8 *buffer) { int loop; printf("int loop;\n"); dolheader *hdr = (dolheader *)buffer; printf("hdr->bsssize %i\n", hdr->bsssize); memset((void *)hdr->bssmem, 0, hdr->bsssize); //stops here 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 validateHeader(u8 *buffer) { if (buffer[0] == 0x0 && buffer[1] == 0x0 && buffer[2] == 0x1) { return 1337; } return 0; } int main(int argc, char** argv){ // main function. Always starts first // Initialise the video system VIDEO_Init(); // This function initialises the attached controllers WPAD_Init(); // Obtain the preferred video mode from the system // This will correspond to the settings in the Wii menu rmode = VIDEO_GetPreferredMode(NULL); // Allocate memory for the display in the uncached region xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); // Initialise the console, required for printf console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); // Set up the video registers with the chosen mode VIDEO_Configure(rmode); // Tell the video hardware where our display memory is VIDEO_SetNextFramebuffer(xfb); // Make the display visible VIDEO_SetBlack(FALSE); // Flush the video register changes to the hardware VIDEO_Flush(); // Wait for Video setup to complete VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); printf("\x1b[2;0H"); printf("start\n"); fatInitDefault(); u8 *bufPtr = (u8 *) 0x92000000; int size_of_file; printf("open dol\n"); int filedes = open("sd:/apps/pngmove/boot.dol",O_RDWR); if(filedes < 0){ printf("null dol\n"); sleep(1); return 0; } printf("get size\n"); size_of_file = lseek(filedes, 0, SEEK_END); lseek(filedes, 0, SEEK_SET); printf("read bufptr %i\n", size_of_file); read(filedes, bufPtr, size_of_file); close(filedes); printf("valid? %i\n", validateHeader(bufPtr)); printf("typedef void (*Entry)()\n"); void (*entry)(); printf("entry = (void (*)())relocateDol(bufPtr);\n"); entry = (void (*)())relocateDol(bufPtr); printf("IOS_ReloadIOS(36);\n"); IOS_ReloadIOS(36); /* Set CPU/BUS clock as Nintendo SDK apps require so. */ *(vu32*)0x800000F8 = 0x0E7BE2C0; *(vu32*)0x800000FC = 0x2B73A840; __lwp_thread_stopmultitasking(entry); printf("entry();\n"); entry(); free(bufPtr); return 0; }