void enable_ES_ioctlv_vector(void) { mload_init(); patch_datas[0]=*((u32 *) (dip_plugin+16*4)); mload_set_ES_ioctlv_vector((void *) patch_datas[0]); mload_close(); }
void Set_DIP_BCA_Datas(u8 *bca_data) { // write in dip_plugin bca data area mload_init(); mload_seek(*((u32 *) (dip_plugin+15*4)), SEEK_SET); // offset 15 (bca_data area) mload_write(bca_data, 64); mload_close(); }
void disableIOSReload(void) { if (mload_init() < 0 || IOS_GetRevision() == 2) return; patch_datas[0] = *((u32 *)(dip_plugin + 16 * 4)); mload_set_ES_ioctlv_vector((void *)patch_datas[0]); mload_close(); }
static void _ExitApp() { //ExitGUIThreads(); //StopGX(); //ShutdownAudio(); SDCard_deInit(); USBDevice_deInit(); mload_set_ES_ioctlv_vector(NULL); mload_close(); }
void load_dip_249() { gprintf("Starting mload\n"); if(mload_init() < 0) return; gprintf("Loading 249 dip..."); int ret = mload_module((void *)dip_plugin_249, size_dip_plugin_249); gprintf("%d\n", ret); mload_close(); }
int load_modules(const u8 * ehcmodule, int ehcmodule_size, const u8 * dip, int dip_size) { if(mload_init() < 0) return -1; dip_plugin = (u8 *) dip; dip_plugin_size = dip_size; mload_elf((u8 *) ehcmodule, &my_data_elf); my_thread_id= mload_run_thread(my_data_elf.start, my_data_elf.stack, my_data_elf.size_stack, my_data_elf.prio); if(my_thread_id < 0) return -2; usleep(350*1000); // Test for IOS int is_ios = mload_get_IOS_base(); u32 dip_address = 0x1377C000; switch(is_ios) { case 36: memcpy(ios_36, dip_plugin, 4); // copy the entry_point memcpy(dip_plugin, ios_36, 4*10); // copy the adresses from the array mload_seek(dip_address, SEEK_SET); // copy dip_plugin in the starlet mload_write(dip_plugin, dip_plugin_size); // enables DIP plugin mload_seek(0x20209040, SEEK_SET); mload_write(ios_36, 4); break; case 37: memcpy(ios_37, dip_plugin, 4); // copy the entry_point memcpy(dip_plugin, ios_37, 4*10); // copy the adresses from the array mload_seek(dip_address, SEEK_SET); // copy dip_plugin in the starlet mload_write(dip_plugin,dip_plugin_size); // enables DIP plugin mload_seek(0x20209030, SEEK_SET); mload_write(ios_37, 4); break; case 38: memcpy(ios_38, dip_plugin, 4); // copy the entry_point memcpy(dip_plugin, ios_38, 4*10); // copy the adresses from the array mload_seek(dip_address, SEEK_SET); // copy dip_plugin in the starlet mload_write(dip_plugin,dip_plugin_size); // enables DIP plugin mload_seek(0x20208030, SEEK_SET); mload_write(ios_38, 4); break; case 57: memcpy(ios_57, dip_plugin, 4); // copy the entry_point memcpy(dip_plugin, ios_57, 4*10); // copy the adresses from the array mload_seek(dip_address, SEEK_SET); // copy dip_plugin in the starlet mload_write(dip_plugin,dip_plugin_size); // enables DIP plugin mload_seek(0x20208030, SEEK_SET); mload_write(ios_57, 4); break; case 60: memcpy(ios_60, dip_plugin, 4); // copy the entry_point memcpy(dip_plugin, ios_60, 4*10); // copy the adresses from the array mload_seek(dip_address, SEEK_SET); // copy dip_plugin in the starlet mload_write(dip_plugin,dip_plugin_size); // enables DIP plugin mload_seek(0x20208030, SEEK_SET); mload_write(ios_60, 4); break; } mload_close(); return 0; }
int load_ehc_module() { int is_ios=0; #if 0 FILE *fp; // WARNING!!!: load external module suspended if(sd_ok && !external_ehcmodule) { fp=fopen("sd:/apps/usbloader_gx/ehcmodule.elf","rb"); if(fp==NULL) fp=fopen("sd:/apps/usbloadergx/ehcmodule.elf","rb"); if(fp!=0) { fseek(fp, 0, SEEK_END); size_external_ehcmodule = ftell(fp); external_ehcmodule= memalign(32, size_external_ehcmodule); if(!external_ehcmodule) {fclose(fp);} else { fseek(fp, 0, SEEK_SET); if(fread(external_ehcmodule,1, size_external_ehcmodule ,fp)!=size_external_ehcmodule) {free(external_ehcmodule); external_ehcmodule=NULL;} fclose(fp); } } } #endif /* if(mload_init()<0) return -1; mload_elf((void *) logmodule, &my_data_elf); my_thread_id= mload_run_thread(my_data_elf.start, my_data_elf.stack, my_data_elf.size_stack, my_data_elf.prio); if(my_thread_id<0) return -1; */ if(!external_ehcmodule) { #ifdef DEBUG_MLOAD gprintf("before mload_init\n"); #endif if(mload_init()<0) return -1; #ifdef DEBUG_MLOAD gprintf("after mload_init\n"); #endif if (IOS_GetRevision() == 4) { #ifdef DEBUG_MLOAD gprintf("Loading ehcmodule v4\n"); #endif mload_elf((void *) ehcmodule_frag_v4_bin, &my_data_elf); } else if (IOS_GetRevision() == 65535) { #ifdef DEBUG_MLOAD gprintf("Loading ehcmodule v5\n"); #endif mload_elf((void *) ehcmodule_frag_v5_bin, &my_data_elf); } else { return -2; } // mload_elf((void *) ehcmodule, &my_data_elf); #ifdef DEBUG_MLOAD gprintf("before mload_run_thread\n"); #endif my_thread_id= mload_run_thread(my_data_elf.start, my_data_elf.stack, my_data_elf.size_stack, my_data_elf.prio); if(my_thread_id<0) return -1; //if(mload_module(ehcmodule, size_ehcmodule)<0) return -1; } else { //if(mload_module(external_ehcmodule, size_external_ehcmodule)<0) return -1; if(mload_init()<0) return -1; mload_elf((void *) external_ehcmodule, &my_data_elf); my_thread_id= mload_run_thread(my_data_elf.start, my_data_elf.stack, my_data_elf.size_stack, my_data_elf.prio); if(my_thread_id<0) return -1; } usleep(350*1000); // Test for IOS #if 0 mload_seek(0x20207c84, SEEK_SET); mload_read(patch_datas, 32); if(patch_datas[0]==0x6e657665 ) { is_ios=38; } else { is_ios=36; } #endif is_ios=mload_get_IOS_base(); switch(is_ios) { case 36: memcpy(ios_36, dip_plugin, 4); // copy the entry_point memcpy(dip_plugin, ios_36, 4*10); // copy the adresses from the array mload_seek(0x1377E000, SEEK_SET); // copy dip_plugin in the starlet mload_write(dip_plugin,size_dip_plugin); // enables DIP plugin mload_seek(0x20209040, SEEK_SET); mload_write(ios_36, 4); break; case 37: memcpy(ios_37, dip_plugin, 4); // copy the entry_point memcpy(dip_plugin, ios_37, 4*10); // copy the adresses from the array mload_seek(0x1377E000, SEEK_SET); // copy dip_plugin in the starlet mload_write(dip_plugin,size_dip_plugin); // enables DIP plugin mload_seek(0x20209030, SEEK_SET); mload_write(ios_37, 4); break; case 38: memcpy(ios_38, dip_plugin, 4); // copy the entry_point memcpy(dip_plugin, ios_38, 4*10); // copy the adresses from the array mload_seek(0x1377E000, SEEK_SET); // copy dip_plugin in the starlet mload_write(dip_plugin,size_dip_plugin); // enables DIP plugin mload_seek(0x20208030, SEEK_SET); mload_write(ios_38, 4); break; case 57: memcpy(ios_57, dip_plugin, 4); // copy the entry_point memcpy(dip_plugin, ios_57, 4*10); // copy the adresses from the array mload_seek(0x1377E000, SEEK_SET); // copy dip_plugin in the starlet mload_write(dip_plugin,size_dip_plugin); // enables DIP plugin mload_seek(0x20208030, SEEK_SET); mload_write(ios_57, 4); break; case 60: memcpy(ios_60, dip_plugin, 4); // copy the entry_point memcpy(dip_plugin, ios_60, 4*10); // copy the adresses from the array mload_seek(0x1377E000, SEEK_SET); // copy dip_plugin in the starlet mload_write(dip_plugin,size_dip_plugin); // enables DIP plugin mload_seek(0x20208030, SEEK_SET); mload_write(ios_60, 4); break; } mload_close(); return 0; }
int load_fatffs_module(u8 *discid) { static char fs[] ATTRIBUTE_ALIGN(32) = "fat"; s32 hid = -1, fd = -1; static char file_name[256] ALIGNED(0x20)="SD:"; int n; char *p; s32 ret; p=&file_name[0]; if(mload_init()<0) return -1; mload_elf((void *) fatffs_module_bin, &my_data_elf); my_thread_id= mload_run_thread(my_data_elf.start, my_data_elf.stack, my_data_elf.size_stack, my_data_elf.prio); if(my_thread_id<0) return -1; global_mount &=~0xc; if(discid) { sd_ok=ud_ok=1; /* Function get_fat_name not implemented, this should return the path to the save file */ // p=get_fat_name(discid); p = NULL; sd_ok=ud_ok=0; if(!p) return -1; global_mount &=~0xf; // change 'ud:' by 'usb:' if(p[0]=='U') {global_mount|=2;file_name[0]='U';file_name[1]='S';file_name[2]='B';memcpy(file_name+3, (void *)p+2, 253);} else {global_mount|=1;memcpy(file_name, (void *) p, 256);} // copy filename to dip_plugin filename area mload_seek(*((u32 *) (dip_plugin+14*4)), SEEK_SET); // offset 14 (filename Address - 256 bytes) mload_write(file_name, sizeof(file_name)); mload_close(); } else { if((global_mount & 3)==0) return 0; if(global_mount & 1) p[0]='s'; if(global_mount & 2) p[0]='u'; } usleep(350*1000); /* Create heap */ if (hid < 0) { hid = iosCreateHeap(0x100); if (hid < 0) return -1; } /* Open USB device */ fd = IOS_Open(fs, 0); if (fd < 0) { if(hid>=0) { iosDestroyHeap(hid); hid=-1; } return -1; } n=30; // try 20 times while(n>0) { if((global_mount & 10)==2) {ret=IOS_IoctlvFormat(hid, fd, IOCTL_FAT_MOUNTUSB, ":");if(ret==0) global_mount|=8;} else {ret=IOS_IoctlvFormat(hid, fd, IOCTL_FAT_MOUNTSD, ":");if(ret==0) {global_mount|=4;}} if((global_mount & 7)==3 && ret==0) {ret=IOS_IoctlvFormat(hid, fd, IOCTL_FAT_MOUNTSD, ":");if(ret==0) global_mount|=4;} if((global_mount & 3)==((global_mount>>2) & 3) && (global_mount & 3)) {ret=0;break;} else ret=-1; //ret=IOS_IoctlvFormat(hid, fd, IOCTL_FAT_MOUNTSD, ":"); //if(ret==0) break; usleep(500*1000); n--; }
int main(int argc, char **argv) { int ret; VIDEO_Init(); //Inicialización del Vídeo. rmode = VIDEO_GetPreferredMode(NULL); //mediante esta función rmode recibe el valor de tu modo de vídeo. xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); //inicialización del buffer. console_init(xfb,20,20,rmode->fbWidth,rmode-> //inicialización de la consola. xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); VIDEO_Configure(rmode); //configuración del vídeo. VIDEO_SetNextFramebuffer(xfb); //Configura donde guardar el siguiente buffer . VIDEO_SetBlack(FALSE); //Hace visible el display . VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); SYS_SetResetCallback(reset_call); IOS_ReloadIOS(222); sleep(1); /* secuencias de escape \33[2J -> borra pantalla y posiciona en 1,1 \33[1;1H -> posiciona en 1,1 \33[42m -> color de fondo verde (0->negro, 1->rojo, 2->verde, 3-> amarillo, 4->azul, 5->magenta 6->cyan 7->blanco ) \33[32m -> color de letras verde */ printf("\33[2J\n\n\n \33[42m dev/mload Test \33[40m \n\n\n\n"); ret=mload_init(); if(ret<0) { printf("fail to get dev/mload\n"); goto out; } else { u32 addr; int len; printf("Hello!: my name is dev/mload and my thread id is %i\n", mload_get_thread_id()); mload_get_load_base(&addr, &len); printf("You have from 0x%x to 0x%x to work\n\n", addr, addr+len-1); } /* mload_elf((void *) ehcmodule_elf, &my_data_elf); my_thread_id=mload_run_thread(my_data_elf.start, my_data_elf.stack, my_data_elf.size_stack, my_data_elf.prio); */ printf("Loading example1.elf (Starlet)\n"); if(((u32) example1_elf) & 3) {printf("Unaligned elf!\n"); goto out;} mload_elf((void *) example1_elf, &my_data_elf); printf("Running... at 0x%x\n", (u32) my_data_elf.start); my_thread_id=mload_run_thread(my_data_elf.start, my_data_elf.stack, my_data_elf.size_stack, my_data_elf.prio); if(my_thread_id<0) {printf("fail to init the starlet thread: %i\n", my_thread_id); goto out;} printf("Module thread id: %i Priority in elf: 0x%x\n", my_thread_id, my_data_elf.prio); printf("The example Module counts seconds and report the thread id and the priority\n"); { #if 0 int n,m; sleep(1); #define UMS_BASE (('U'<<24)|('M'<<16)|('S'<<8)) #define USB_IOCTL_UMS_INIT (UMS_BASE+0x1) s32 hid2 = -1; hid2 = iosCreateHeap(1024); n=IOS_Open(ehc_fs, 0); if(n<0) printf("Error: device not found\n"); else { printf("OK\n"); /* Initialize USB storage */ m=IOS_IoctlvFormat(hid2, n, USB_IOCTL_UMS_INIT, ":"); } #endif } while(1) { static u32 data[8] ATTRIBUTE_ALIGN(32); if(exit_by_reset) break; mload_seek(0x13740000, SEEK_SET); mload_read(&data,32); printf("\33[16;16H Starlet activity: %i Thid: %i Prio: 0x%x \n",data[0],data[1],data[2]); VIDEO_WaitVSync(); } // you can stops the Starlet thread using this function: mload_stop_thread(my_thread_id); out: mload_close(); VIDEO_WaitVSync(); sleep(4); return 0; }