19#ifdef BUILDING_XMCSERV
20static const u8 XMCSERV_RpcCmd[2][16] =
61static void *rpc_funcs_array[21] = {
74 (
void *)sceMcSetFileInfo,
75 (
void *)sceMcEraseBlock,
76 (
void *)sceMcReadPage,
77 (
void *)sceMcWritePage,
78 (
void *)sceMcUnformat,
80#ifdef BUILDING_XMCSERV
81 (
void *)sceMcGetInfo2,
85#ifdef BUILDING_XMCSERV
86 (
void *)sceMcGetEntSpace,
90#ifdef BUILDING_XMCSERV
91 (
void *)sceMcCheckBlock,
97static int mcserv_tidS_0400;
98static int mcserv_in_rpc_0400 = 0;
103static u8 mcserv_rpc_buf[2048]
__attribute__((__aligned__(4)));
106#define MCSERV_BUFSIZE 8192
112int _start(
int argc,
char *argv[],
void *startaddr,
ModuleInfo_t *mi)
115 register int thread_id;
122 sio_init(38400, 0, 0, 0, 0);
124 DPRINTF(
"_start...\n");
131 if (mcserv_in_rpc_0400)
133 return MODULE_REMOVABLE_END;
137 release_res = ReleaseLibraryEntries(&_exp_mcserv);
139 if (release_res == 0 || release_res == -213)
141 TerminateThread(mcserv_tidS_0400);
142 DeleteThread(mcserv_tidS_0400);
143 sceSifRemoveRpc(&mcserv_sdS_0400, &mcserv_qdS_0400);
144 sceSifRemoveRpcQueue(&mcserv_qdS_0400);
145 return MODULE_NO_RESIDENT_END;
147 return MODULE_REMOVABLE_END;
151 DPRINTF(
"registering exports...\n");
152 if (RegisterLibraryEntries(&_exp_mcserv) != 0)
157 DPRINTF(
"starting RPC thread...\n");
158 thread_param.attr = TH_C;
159 thread_param.thread = (
void *)thread_rpc_S_0400;
160 thread_param.priority = 0x68;
161 thread_param.stacksize = 0x1000;
162 thread_param.option = 0;
164 thread_id = CreateThread(&thread_param);
165 mcserv_tidS_0400 = thread_id;
167 StartThread(thread_id, 0);
169 DPRINTF(
"_start returns MODULE_RESIDENT_END...\n");
171 if (mi && ((mi->
newflags & 2) != 0))
173 return MODULE_RESIDENT_END;
177 DPRINTF(
"_start returns MODULE_NO_RESIDENT_END...\n");
179 return MODULE_NO_RESIDENT_END;
183void thread_rpc_S_0400(
void* arg)
187 if (!sceSifCheckInit())
191 sceSifSetRpcQueue(&mcserv_qdS_0400, GetThreadId());
192 sceSifRegisterRpc(&mcserv_sdS_0400, 0x80000400, (
void *)cb_rpc_S_0400, &mcserv_rpc_buf, NULL, NULL, &mcserv_qdS_0400);
193 sceSifRpcLoop(&mcserv_qdS_0400);
197void *cb_rpc_S_0400(u32 fno,
void *buf,
int size)
200 int (*rpc_func)(void);
205#ifdef BUILDING_XMCSERV
209 for (i=0; i<16; i++) {
210 if (fno == XMCSERV_RpcCmd[0][i]) {
211 fno = XMCSERV_RpcCmd[1][i];
220 return (
void *)&rpc_stat;
225 rpc_func = (
void *)rpc_funcs_array[fno];
227 mcserv_in_rpc_0400 = 1;
230 rpc_stat.result = rpc_func();
234 mcserv_in_rpc_0400 = 0;
236 return (
void *)&rpc_stat;
243#ifdef BUILDING_XMCSERV
247 r = _McInit(&mcserv_rpc_buf);
249#ifdef BUILDING_XMCSERV
252 rpc_stat.mcserv_version = MODVER;
263 return _McOpen(&mcserv_rpc_buf);
269 return _McClose(&mcserv_rpc_buf);
275 return _McRead(&mcserv_rpc_buf);
281 return _McRead2(&mcserv_rpc_buf);
287 return _McWrite(&mcserv_rpc_buf);
293 return _McSeek(&mcserv_rpc_buf);
299 return _McGetDir(&mcserv_rpc_buf);
305 return _McFormat(&mcserv_rpc_buf);
309int sceMcUnformat(
void)
311 return _McUnformat(&mcserv_rpc_buf);
315int sceMcGetInfo(
void)
317 return _McGetInfo(&mcserv_rpc_buf);
321#ifdef BUILDING_XMCSERV
322int sceMcGetInfo2(
void)
324 return _McGetInfo2(&mcserv_rpc_buf);
331 return _McDelete(&mcserv_rpc_buf);
337 return _McFlush(&mcserv_rpc_buf);
343 return _McChDir(&mcserv_rpc_buf);
347int sceMcEraseBlock(
void)
349 return _McEraseBlock(&mcserv_rpc_buf);
353int sceMcReadPage(
void)
355 return _McReadPage(&mcserv_rpc_buf);
359int sceMcWritePage(
void)
361 return _McWritePage(&mcserv_rpc_buf);
365int sceMcSetFileInfo(
void)
367 return _McSetFileInfo(&mcserv_rpc_buf);
371#ifdef BUILDING_XMCSERV
372int sceMcGetEntSpace(
void)
374 return _McGetEntSpace(&mcserv_rpc_buf);
379#ifdef BUILDING_XMCSERV
380int sceMcCheckBlock(
void)
382 return _McCheckBlock(&mcserv_rpc_buf);
387int _McInit(
void *rpc_buf)
391 DPRINTF(
"_McInit fd %d offset %d\n", dP->fd, dP->offset);
393#ifndef BUILDING_XMCSERV
397 if (dP->offset == -217)
400 McSetPS1CardFlag(ps1flag);
404 return McRetOnly(dP->fd);
408int _McOpen(
void *rpc_buf)
412 DPRINTF(
"_McOpen port%d slot%d file %s flags %d\n", nP->port, nP->slot, nP->name, nP->flags);
414 return McOpen(nP->port, nP->slot, nP->name, nP->flags);
418int _McClose(
void *rpc_buf)
422 DPRINTF(
"_McClose fd %d\n", dP->fd);
424 return McClose(dP->fd);
428int _McSeek(
void *rpc_buf)
432 DPRINTF(
"_McSeek fd %d offset %d origin %d\n", dP->fd, dP->offset, dP->origin);
434 return McSeek(dP->fd, dP->offset, dP->origin);
438int _McRead(
void *rpc_buf)
441 register int file_offset, status;
442 register int left_to_read, size_readed, size_to_read;
448 DPRINTF(
"_McRead fd %d ee buffer addr %x size %d\n", dP->fd, (
int)dP->buffer, dP->size);
463 eP.size1 = (((int)(eedata)-1) & 0xfffffff0) - ((int)(eedata) - 16);
465 eP.size2 = (dP->size - eP.size1) & 0x0f;
466 left_to_read = (dP->size - eP.size1) - eP.size2;
469 eP.dest2 = (
void *)((u8 *)eedata + eP.size1 + left_to_read);
472 size_readed = McRead(dP->fd, eP.src1, eP.size1);
474 if (size_readed < 0) {
480 file_offset = size_readed;
482 eedata = (
void *)((u8 *)eedata + size_readed);
484 if (size_readed != eP.size1) {
485 eP.size1 = size_readed;
495 while (left_to_read > 0) {
497 size_to_read = left_to_read;
499 if (left_to_read > MCSERV_BUFSIZE)
500 size_to_read = MCSERV_BUFSIZE;
502 size_readed = McRead(dP->fd, mcserv_buf, size_to_read);
504 if (size_readed < 0) {
509 dmaStruct.src = (
void *)mcserv_buf;
510 dmaStruct.dest = (
void *)eedata;
511 dmaStruct.size = size_readed;
515 sceSifSetDma(&dmaStruct, 1);
517 file_offset += size_readed;
518 left_to_read -= size_readed;
522 eedata = (
void *)((u8 *)eedata + size_readed);
524 if (size_to_read != size_readed) {
535 size_readed = McRead(dP->fd, eP.src2, eP.size2);
537 if (size_readed < 0) {
542 file_offset += size_readed;
543 eP.size2 = size_readed;
547 dmaStruct.src = (
void *)&eP;
548 dmaStruct.dest = (
void *)dP->param;
553 status = sceSifSetDma(&dmaStruct, 1);
556 while (sceSifDmaStat(status) >= 0)
559 if (size_readed != 0)
566int _McRead2(
void *rpc_buf)
569 register int file_offset, status;
570 register int left_to_read, size_readed, size_to_read;
576 DPRINTF(
"_McRead2 fd %d ee buffer addr %x size %d\n", dP->fd, (
int)dP->buffer, dP->size);
591 eP.size1 = (((u32)(eedata)-1) & 0xffffffc0) - ((u32)(eedata) - 64);
593 eP.size2 = (dP->size - eP.size1) & 0x3f;
594 left_to_read = (dP->size - eP.size1) - eP.size2;
597 eP.dest2 = (
void *)((u8 *)eedata + eP.size1 + left_to_read);
600 size_readed = McRead(dP->fd, eP.src1, eP.size1);
602 if (size_readed < 0) {
608 file_offset = size_readed;
610 eedata = (
void *)((u8 *)eedata + size_readed);
612 if (size_readed != eP.size1) {
613 eP.size1 = size_readed;
623 while (left_to_read > 0) {
625 size_to_read = left_to_read;
627 if (left_to_read > MCSERV_BUFSIZE)
628 size_to_read = MCSERV_BUFSIZE;
630 size_readed = McRead(dP->fd, mcserv_buf, size_to_read);
632 if (size_readed < 0) {
637 if (size_readed == size_to_read) {
638 dmaStruct.size = size_readed;
642 eP.size2 = size_readed & 0x3f;
643 if ((size_readed & 0x3f) != 0) {
644 eP.dest2 = (
void *)((u8 *)eedata + (size_readed & 0xffffffc0));
645 memcpy(eP.src2, (
void *)(mcserv_buf + (size_readed & 0xffffffc0)), size_readed & 0x3f);
648 if (eP.size2 == size_readed)
649 goto skip_dma_transfer;
651 dmaStruct.size = size_readed - eP.size2;
654 dmaStruct.src = (
void *)mcserv_buf;
655 dmaStruct.dest = (
void *)eedata;
659 sceSifSetDma(&dmaStruct, 1);
663 file_offset += size_readed;
664 left_to_read -= size_readed;
665 eedata = (
void *)((u8 *)eedata + size_readed);
667 if (size_to_read != size_readed) {
677 size_readed = McRead(dP->fd, eP.src2, eP.size2);
679 if (size_readed < 0) {
684 file_offset += size_readed;
685 eP.size2 = size_readed;
689 dmaStruct.src = (
void *)&eP;
690 dmaStruct.dest = (
void *)dP->param;
695 status = sceSifSetDma(&dmaStruct, 1);
698 while (sceSifDmaStat(status) >= 0)
701 if (size_readed != 0)
708int _McWrite(
void *rpc_buf)
712 register int size_written;
714 DPRINTF(
"_McWrite fd %d ee buffer addr %x size %d\n", dP->fd, (
int)dP->buffer, dP->size);
718 if (dP->origin != 0) {
719 size_written = McWrite(dP->fd, dP->data, dP->origin);
721 if (size_written != dP->origin)
725 while (dP->size > 0) {
726 register int size_to_write, r;
728 size_to_write = dP->size;
730 if (dP->size > MCSERV_BUFSIZE)
731 size_to_write = MCSERV_BUFSIZE;
733 sceSifGetOtherData(&rD, dP->buffer, &mcserv_buf, size_to_write, 0);
735 r = McWrite(dP->fd, &mcserv_buf, size_to_write);
736 if (r != size_to_write) {
739 return r + size_written;
742 size_written += size_to_write;
743 dP->size -= size_to_write;
745 dP->buffer += size_to_write;
752int _McGetDir(
void *rpc_buf)
755 register int status, file_entries, flags, r;
759 DPRINTF(
"_McGetDir port%d slot%d dir %s flags %d maxent %d mcT addr %x\n", nP->port, nP->slot, nP->name, nP->flags, nP->maxent, (
int)nP->mcT);
767 while (nP->maxent > -1) {
769 r = McGetDir(nP->port, nP->slot, nP->name, flags & 0xffff, 1, (
sceMcTblGetDir *)mcserv_buf);
777 dmaStruct.src = (
void *)mcserv_buf;
778 dmaStruct.dest = (
void *)nP->mcT;
783 status = sceSifSetDma(&dmaStruct, 1);
795 while (sceSifDmaStat(status) >= 0)
802int _McChDir(
void *rpc_buf)
805 register int status, r;
809 DPRINTF(
"_McChDir port%d slot%d newdir %s\n", nP->port, nP->slot, nP->name);
811 r = McChDir(nP->port, nP->slot, nP->name, (
char *)mcserv_buf);
813 dmaStruct.src = (
void *)mcserv_buf;
814 dmaStruct.dest = (
void *)nP->curdir;
815 dmaStruct.size = 1024;
819 status = sceSifSetDma(&dmaStruct, 1);
822 while (sceSifDmaStat(status) >= 0)
829int _McFormat(
void *rpc_buf)
833 DPRINTF(
"_McFormat port%d slot%d\n", dP->port, dP->slot);
835 return McFormat(dP->port, dP->slot);
839int _McUnformat(
void *rpc_buf)
843 DPRINTF(
"_McUnformat port%d slot%d\n", dP->port, dP->slot);
845 return McUnformat(dP->port, dP->slot);
849int _McGetInfo(
void *rpc_buf)
852 register int status, mc_free, r;
857 DPRINTF(
"_McGetInfo port%d slot%d\n", dP->port, dP->slot);
861 r = McDetectCard(dP->port, dP->slot);
864 eP.type = McGetMcType(dP->port, dP->slot);
871 mc_free = McGetFreeClusters(dP->port, dP->slot);
878 dmaStruct.src = (
void *)&eP;
879 dmaStruct.dest = (
void *)dP->param;
884 status = sceSifSetDma(&dmaStruct, 1);
887 while (sceSifDmaStat(status) >= 0)
897#ifdef BUILDING_XMCSERV
898int _McGetInfo2(
void *rpc_buf)
901 register int status, mc_free, r;
906 DPRINTF(
"_McGetInfo2 port%d slot%d\n", dP->port, dP->slot);
910 r = McDetectCard2(dP->port, dP->slot);
913 eP.type = McGetMcType(dP->port, dP->slot);
921 if (dP->offset > 0) {
922 mc_free = McGetFreeClusters(dP->port, dP->slot);
932 if (McGetFormat(dP->port, dP->slot) > 0)
938 dmaStruct.src = (
void *)&eP;
939 dmaStruct.dest = (
void *)dP->param;
944 status = sceSifSetDma(&dmaStruct, 1);
947 while (sceSifDmaStat(status) >= 0)
958#ifdef BUILDING_XMCSERV
959int _McGetEntSpace(
void *rpc_buf)
963 DPRINTF(
"_McGetEntSpace port%d slot%d dirname %s\n", nP->port, nP->slot, nP->name);
965 return McGetEntSpace(nP->port, nP->slot, nP->name);
970int _McDelete(
void *rpc_buf)
974 DPRINTF(
"_McDelete port%d slot%d file %s flags %d\n", nP->port, nP->slot, nP->name, nP->flags);
976 return McDelete(nP->port, nP->slot, nP->name, nP->flags);
980int _McFlush(
void *rpc_buf)
984 DPRINTF(
"_McFlush fd %d\n", dP->fd);
986 return McFlush(dP->fd);
990int _McEraseBlock(
void *rpc_buf)
996 DPRINTF(
"_McEraseBlock port%d slot%d offset %d\n", dP->port, dP->slot, dP->offset);
998 dP->port = (dP->port & 1) + 2;
1000 if (McGetMcType(dP->port, dP->slot) == 2) {
1001 register int pagenum;
1003 r = McEraseBlock(dP->port, dP->offset, NULL, NULL);
1007 if (dP->origin == -1)
1010 memset(mcserv_buf, dP->origin, 512);
1012 McDataChecksum(&mcserv_buf[0], &eccbuf[0]);
1013 McDataChecksum(&mcserv_buf[128], &eccbuf[3]);
1014 McDataChecksum(&mcserv_buf[256], &eccbuf[6]);
1015 McDataChecksum(&mcserv_buf[384], &eccbuf[9]);
1020 r = McWritePage(dP->port, dP->slot, (dP->offset << 4) + pagenum, mcserv_buf, eccbuf);
1022 }
while (++pagenum < 16);
1028 memset(mcserv_buf, dP->origin, 128);
1030 r = McWritePS1PDACard(dP->port, dP->slot, dP->offset, mcserv_buf);
1036int _McReadPage(
void *rpc_buf)
1040 register int status, fastsize, r, i, j;
1044 DPRINTF(
"_McReadPage port%d slot%d page %d\n", dP->port, dP->slot, dP->fd);
1046 eP.dest1 = dP->buffer;
1048 fastsize = ((u32)dP->buffer) & 0xf;
1049 dP->port = (dP->port & 1) + 2;
1051 if (McGetMcType(dP->port, dP->slot) == 2) {
1053 McReadPage(dP->port, dP->slot, dP->fd, (
void *)(mcserv_buf + fastsize));
1056 memset((
void *)(mcserv_buf + fastsize), 0, 512);
1057 r = McReadPS1PDACard(dP->port, dP->slot, dP->fd, (
void *)(mcserv_buf + fastsize));
1066 eP.src1[i] = mcserv_buf[j];
1074 eP.src1[i] = mcserv_buf[512 + j];
1080 dmaStruct.src = (
void *)(mcserv_buf + 16);
1081 dmaStruct.dest = (
void *)(dP->buffer - (fastsize - 16));
1082 dmaStruct.size = 496;
1087 dmaStruct.src = (
void *)mcserv_buf;
1088 dmaStruct.dest = (
void *)dP->buffer;
1089 dmaStruct.size = 512;
1094 sceSifSetDma(&dmaStruct, 1);
1097 dmaStruct.src = (
void *)&eP;
1098 dmaStruct.dest = (
void *)dP->param;
1103 status = sceSifSetDma(&dmaStruct, 1);
1106 while (sceSifDmaStat(status) >= 0)
1113int _McWritePage(
void *rpc_buf)
1116 register int fastsize, i, j;
1120 DPRINTF(
"_McWritePage port%d slot%d page %d\n", dP->port, dP->slot, dP->fd);
1122 fastsize = ((u32)dP->buffer) & 0xf;
1126 sceSifGetOtherData(&rD, (
void *)(dP->buffer - (fastsize - 16)), &mcserv_buf, 496, 0);
1130 mcserv_buf[i] = dP->data[i - fastsize];
1140 while (i < fastsize) {
1141 mcserv_buf[496 + j] = dP->data[j - fastsize];
1150 sceSifGetOtherData(&rD, dP->buffer, &mcserv_buf, 512, 0);
1154 McDataChecksum((
void *)(mcserv_buf + fastsize), &eccbuf[0]);
1155 McDataChecksum(&mcserv_buf[128], &eccbuf[3]);
1156 McDataChecksum(&mcserv_buf[256], &eccbuf[6]);
1157 McDataChecksum(&mcserv_buf[384], &eccbuf[9]);
1159 return McWritePage((dP->port & 1) | 2, dP->slot, dP->fd, (
void *)(mcserv_buf + fastsize), eccbuf);
1163int _McSetFileInfo(
void *rpc_buf)
1168 DPRINTF(
"_McSetFileInfo port%d slot%d file %s flags %d\n", nP->port, nP->slot, nP->name, nP->flags);
1170 sceSifGetOtherData(&rD, (
void *)nP->mcT, &mcserv_buf, sizeof (
sceMcTblGetDir), 0);
1172 return McSetFileInfo(nP->port, nP->slot, nP->name, (
sceMcTblGetDir *)mcserv_buf, nP->flags);
1176#ifdef BUILDING_XMCSERV
1177int _McCheckBlock(
void *rpc_buf)
1181 DPRINTF(
"_McCheckBlock port%d slot%d block %d\n", dP->port, dP->slot, dP->offset);
1183 return McCheckBlock(dP->port, dP->slot, dP->offset);
int CpuResumeIntr(int state)
int CpuSuspendIntr(int *state)