Advertisement
Yosh

kermit_flashfs.c

Aug 12th, 2012
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.40 KB | None | 0 0
  1. #include <pspiofilemgr.h>
  2. #include <pspsysclib.h>
  3. #include <pspsysevent.h>
  4. #include <pspthreadman_kernel.h>
  5. #include <psputilsforkernel.h>
  6. #include <pspkdebug.h>
  7. #include <pspkernel.h>
  8. #include <pspintrman_kernel.h>
  9.  
  10. #define SCE_ERROR_ERRNO_DEVICE_NOT_FOUND 0x80010013
  11. #define SCE_ERROR_ERRNO_FILE_INVALID_ADDR 0x8001000E
  12. #define SCE_USER_ERROR_ILLEGAL_ARGUMENT 0x80010016
  13. #define SCE_ERROR_ERRNO_INVALID_FILE_DESCRIPTOR 0x80010009
  14.  
  15.  
  16.  
  17. PSP_MODULE_INFO("sceKermitFlashfs_driver", 0x1007, 1, 0);
  18.  
  19.  
  20. FileInfo openedFiles[MAX_OPENED_FILES]; // 23A0
  21.  
  22. PspIoDrvFuncs g_207C = {
  23.     .IoInit = &sub_14E8,
  24.     .IoExit = &sub_157C,
  25.     .IoOpen = &sub_00E4,
  26.     .IoClose = &sub_160C,
  27.     .IoRead = &sub_01DC,
  28.     .IoWrite = &sub_05C8,
  29.     .IoLseek = &sub_07C8,
  30.     .IoIoctl = &sub_1628,
  31.     .IoRemove = &sub_0948,
  32.     .IoMkdir = &sub_0A74,
  33.     .IoRmdir = &sub_0BB0,
  34.     .IoDopen = &sub_16A0,
  35.     .IoDclose = &sub_16C4,
  36.     .IoDread = &sub_0CDC,
  37.     .IoGetstat = &sub_0EB0,
  38.     .IoChstat = &sub_1068,
  39.     .IoRename = &sub_120C,
  40.     .IoChdir = &sub_13BC,
  41.     .IoMount = NULL,
  42.     .IoUmount = NULL,
  43.     .IoDevctl = &sub_16E0,
  44.     .IoUnk21 = NULL,
  45. };
  46.  
  47. PspIoDrvFuncs g_20D4 = {
  48.     .IoInit = &sub_14E8,
  49.     .IoExit = &sub_157C,
  50.     .IoOpen = &sub_00E4,
  51.     .IoClose = &sub_160C,
  52.     .IoRead = &sub_01DC,
  53.     .IoWrite = NULL,
  54.     .IoLseek = NULL,
  55.     .IoIoctl = NULL,
  56.     .IoRemove = NULL,
  57.     .IoMkdir = NULL,
  58.     .IoRmdir = NULL,
  59.     .IoDopen = NULL,
  60.     .IoDclose = NULL,
  61.     .IoDread = NULL,
  62.     .IoGetstat = &sub_0EB0,
  63.     .IoChstat = NULL,
  64.     .IoRename = NULL,
  65.     .IoChdir = NULL,
  66.     .IoMount = &sub_1714,
  67.     .IoUmount = &sub_171C,
  68.     .IoDevctl = NULL,
  69.     .IoUnk21 = NULL,
  70. };
  71.  
  72. PspIoDrv g_212C = {"flash", 0x10, 0x01, "FLASH file", &g_207C};
  73. PspIoDrv g_2140 = {"flashfat", 0x10, 0x01, "FLASH fat file", &g_20D4};
  74.  
  75. PspSysEventHandler g_2350 = {
  76.     .size = 0x04,
  77.     .name = "sceKermitFlashfs",
  78.     .type_mask = 0x00FFFF00,
  79.     .handler = &sub_170C;
  80.     .r28 = 0,
  81.     .busy = 0,
  82.     .next = NULL,
  83.     .reserved[0] = 0,
  84.     .reserved[1] = 0,
  85.     .reserved[2] = 0,
  86.     .reserved[3] = 0,
  87.     .reserved[4] = 0,
  88.     .reserved[5] = 0,
  89.     .reserved[6] = 0,
  90.     .reserved[7] = 0,
  91.     .reserved[8] = 0,
  92. };
  93.  
  94. u32 g_2390;
  95. u32 g_2394;
  96. u32 g_2398;
  97. u32 g_239C;
  98.  
  99. int module_bootstart(void)
  100. {
  101.     sceKernelMemset(0xAA120000, 0, 0x8000);
  102.     g_2398 = 0xAA124000;
  103.     g_2394 = 0xAA120000;
  104.    
  105.     g_239C = sceKernelCreateMutex("SceKermitFlashfsFile", 0x100, 0, 0);
  106.     g_2390 = g_239C;
  107.     if(g_2390 <= 0) return 1;
  108.    
  109.     sceIoDelDrv("flashfat");
  110.     if(sceIoAddDrv(&g_2140) >= 0)
  111.     {
  112.         sceIoDelDrv("flash");
  113.         if(sceIoAddDrv(&g_212C) >= 0)
  114.         {
  115.             sceKernelRegisterSysEventHandler(&g_2350);
  116.             return 0;
  117.         }
  118.     }
  119.    
  120.     sceKernelDeleteMutex(g_2390);
  121.     return 1;
  122. }
  123.  
  124. int sub_14E8(PspIoDrvArg *arg) //IoInit
  125. {
  126.     u8 buf[128];
  127.     u32 resp[2];
  128.     u32 argc;
  129.     u32 size = 0xC;
  130.     void *alignedBuf = ALIGN_64(buf + 63);
  131.    
  132.     sceKernelDcacheInvalidateRange(alignedBuf, 0x40);
  133.    
  134.     KermitPacket *packet = KERMIT_PACKET(alignedBuf);
  135.    
  136.    
  137.     argc = 0;
  138.     sceKermitMemory_driver_AAF047AC(packet, argc, arg, size, KERMIT_OUTPUT_MODE | KERMIT_INPUT_MODE);
  139.    
  140.     argc = 1;
  141.     sceKermit_driver_4F75AA05(packet, KERMIT_MODE_FLASHFS, KERMIT_CMD_INIT_FS, argc, KERMIT_CALLBACK_DISABLE, resp);
  142.    
  143.     // Receive Vita data
  144.     sceKermitMemory_driver_90B662D0(arg, size);
  145.    
  146.    
  147.     return resp[0];
  148. }
  149.  
  150. // IoWrite
  151. int sub_05C8(SceIoIob *iob, const char *data, int len)
  152. {
  153.     u8 buf[128];
  154.     u32 resp[2];
  155.     int errCode = 0;
  156.     void *alignedBuf = ALIGN_64(buf + 63);
  157.     u32 cust = alignedBuf;
  158.    
  159.     sceKernelDcacheInvalidateRange(alignedBuf, 0x40);
  160.    
  161.    
  162.     // asm("sra %0, %1, 31" : "=r" (cust) : "r" (cust));
  163.     // KermitPacket *packet = alignedBuf | (((u32)cust + 2) << 29);
  164.     KermitPacket *packet = KERMIT_PACKET(alignedBuf);
  165.    
  166.     if ( iob->fs_num < 5 )
  167.     {
  168.         //  Check address
  169.         if ( ( (data & 0x1FFFC000 == 0x10000) && ((0b110101 >> (data >> 29)) & 1) ) || /* Scratchpad &  0-1 4-5 8-9 A-B */ \
  170.                 ( (data & 0x1F800000 == 0x04000000) && ((0b110101 >> (data >> 29)) & 1) ) || /* VRAM &  0-1 4-5 8-9 A-B */ \
  171.                 ((0x220202 >> (data >> 27)) & 1) )  // 0 4 8 A (and next bit 1)
  172.         {
  173.             if ( len >= 0 )
  174.             {
  175.                 if ( iob->fileInfo >= openedFiles && \
  176.                         iob->fileInfo < (openedFiles + sizeof(openedFiles)) && \
  177.                         iob->fileInfo->fileIob == iob )
  178.                 {
  179.                     int ret;
  180.                     u32 argc;
  181.                     const void *addr = data - (data % 64);
  182.                     ret = sceKernelDcacheWritebackRange(addr, ALIGN_64((data % 64) + len + 63) );
  183.                     if ( ret != 0 ) Kprintf("Failed data cache write back (addr 0x%08x) %08x\n", addr, ret);
  184.                    
  185.                     // first arg
  186.                     *(packet+0x10) = iob->fileInfo->kermitFileId;
  187.                    
  188.                     argc = 1;
  189.                    
  190.                     // Prepares to receive and sets data as 2nd arg
  191.                     sceKermitMemory_driver_AAF047AC(packet, argc, data, len, KERMIT_INPUT_MODE);
  192.                    
  193.                    
  194.                    
  195.                     // 3rd arg
  196.                     *(packet+0x20) = len;
  197.                    
  198.                     argc = 3;
  199.                     sceKermit_driver_4F75AA05(packet, KERMIT_MODE_FLASHFS, KERMIT_CMD_WRITE_FS, argc, KERMIT_CALLBACK_DISABLE, resp);
  200.                    
  201.                     if ( resp[0] > 0)
  202.                     {
  203.                         iob->fileInfo->unk16 += resp[0];
  204.                         iob->fileInfo->unk20 += - KERNEL(resp[0]);
  205.                         if ( iob->fileInfo->unk16 < (u32)resp[0] )  (iob->fileInfo->unk20)++;
  206.                        
  207.                         iob->unk024 = iob->fileInfo->unk16;
  208.                         iob->unk028 = iob->fileInfo->unk20;
  209.                     }
  210.                    
  211.                     errCode = resp[0];
  212.                    
  213.                 }
  214.                 else    errCode = SCE_ERROR_ERRNO_INVALID_FILE_DESCRIPTOR;
  215.             }
  216.             else    errCode = SCE_USER_ERROR_ILLEGAL_ARGUMENT;
  217.         }
  218.         else    errCode = SCE_ERROR_ERRNO_FILE_INVALID_ADDR;
  219.     }
  220.     else    errCode = SCE_ERROR_ERRNO_DEVICE_NOT_FOUND;
  221.    
  222.    
  223.     return errCode;
  224. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement