PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
mcserv.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright (c) 2009 jimmikaelkael
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
11#include "mcserv.h"
12
13// TODO: last sdk 3.1.0 and sdk 3.0.3 has MCSERV module version 0x2,0x10
14// Check what was changed, and maybe port changes.
15// Note: currently is based on the last XMCSERV from BOOTROM:
16// 0x02,0x08
17IRX_ID(MODNAME, 2, 8);
18
19#ifdef BUILDING_XMCSERV
20static const u8 XMCSERV_RpcCmd[2][16] =
21{ // libmc rpc cmd values for XMCMAN/XMCSERV
22 { 0xFE, // CMD_INIT
23 0x01, // CMD_GETINFO
24 0x02, // CMD_OPEN
25 0x03, // CMD_CLOSE
26 0x04, // CMD_SEEK
27 0x05, // CMD_READ
28 0x06, // CMD_WRITE
29 0x0A, // CMD_FLUSH
30 0x0C, // CMD_CHDIR
31 0x0D, // CMD_GETDIR
32 0x0E, // CMD_SETFILEINFO
33 0x0F, // CMD_DELETE
34 0x10, // CMD_FORMAT
35 0x11, // CMD_UNFORMAT
36 0x12, // CMD_GETENTSPACE
37 0x33 // CMD_CHECKBLOCK (calls xmcman_funcs: 45)
38 },
39 { // corresponding internal rpc function
40 0x00, // sceMcInit
41 0x12, // sceMcGetInfo2
42 0x01, // sceMcOpen
43 0x02, // sceMcClose
44 0x05, // sceMcSeek
45 0x11, // sceMcRead2
46 0x04, // sceMcWrite
47 0x0A, // sceMcFlush
48 0x0B, // sceMcChDir
49 0x06, // sceMcGetDir
50 0x0C, // sceMcSetFileInfo
51 0x09, // sceMcDelete
52 0x07, // sceMcFormat
53 0x10, // sceMcUnformat
54 0x13, // sceMcGetEntSpace
55 0x14 // sceMcCheckBlock (calls xmcman_funcs: 45)
56 }
57};
58#endif
59
60// rpc command handling array
61static void *rpc_funcs_array[21] = {
62 (void *)sceMcInit,
63 (void *)sceMcOpen,
64 (void *)sceMcClose,
65 (void *)sceMcRead,
66 (void *)sceMcWrite,
67 (void *)sceMcSeek,
68 (void *)sceMcGetDir,
69 (void *)sceMcFormat,
70 (void *)sceMcGetInfo,
71 (void *)sceMcDelete,
72 (void *)sceMcFlush,
73 (void *)sceMcChDir,
74 (void *)sceMcSetFileInfo,
75 (void *)sceMcEraseBlock,
76 (void *)sceMcReadPage,
77 (void *)sceMcWritePage,
78 (void *)sceMcUnformat,
79 (void *)sceMcRead2,
80#ifdef BUILDING_XMCSERV
81 (void *)sceMcGetInfo2,
82#else
83 (void *)NULL,
84#endif
85#ifdef BUILDING_XMCSERV
86 (void *)sceMcGetEntSpace,
87#else
88 (void *)NULL,
89#endif
90#ifdef BUILDING_XMCSERV
91 (void *)sceMcCheckBlock,
92#else
93 (void *)NULL,
94#endif
95};
96
97static int mcserv_tidS_0400;
98static int mcserv_in_rpc_0400 = 0;
99
100static SifRpcDataQueue_t mcserv_qdS_0400 __attribute__((aligned(16)));
101static SifRpcServerData_t mcserv_sdS_0400 __attribute__((aligned(16)));
102
103static u8 mcserv_rpc_buf[2048] __attribute__((__aligned__(4)));
104static mcRpcStat_t rpc_stat __attribute__((aligned(16)));
105
106#define MCSERV_BUFSIZE 8192
107static u8 mcserv_buf[MCSERV_BUFSIZE] __attribute__((aligned(16)));
108
109extern struct irx_export_table _exp_mcserv;
110
111//--------------------------------------------------------------
112int _start(int argc, char *argv[], void *startaddr, ModuleInfo_t *mi)
113{
114 iop_thread_t thread_param;
115 register int thread_id;
116
117 (void)argc;
118 (void)argv;
119 (void)startaddr;
120
121#ifdef SIO_DEBUG
122 sio_init(38400, 0, 0, 0, 0);
123#endif
124 DPRINTF("_start...\n");
125
126 if (argc < 0)
127 {
128 int release_res;
129 int state;
130
131 if (mcserv_in_rpc_0400)
132 {
133 return MODULE_REMOVABLE_END;
134 }
135
136 CpuSuspendIntr(&state);
137 release_res = ReleaseLibraryEntries(&_exp_mcserv);
138 CpuResumeIntr(state);
139 if (release_res == 0 || release_res == -213)
140 {
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;
146 }
147 return MODULE_REMOVABLE_END;
148 }
149
150 // Register mcserv dummy export table
151 DPRINTF("registering exports...\n");
152 if (RegisterLibraryEntries(&_exp_mcserv) != 0)
153 goto err_out;
154
156
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;
163
164 thread_id = CreateThread(&thread_param);
165 mcserv_tidS_0400 = thread_id;
166
167 StartThread(thread_id, 0);
168
169 DPRINTF("_start returns MODULE_RESIDENT_END...\n");
170
171 if (mi && ((mi->newflags & 2) != 0))
172 mi->newflags |= 0x10;
173 return MODULE_RESIDENT_END;
174
175err_out:
176
177 DPRINTF("_start returns MODULE_NO_RESIDENT_END...\n");
178
179 return MODULE_NO_RESIDENT_END;
180}
181
182//--------------------------------------------------------------
183void thread_rpc_S_0400(void* arg)
184{
185 (void)arg;
186
187 if (!sceSifCheckInit())
188 sceSifInit();
189
190 sceSifInitRpc(0);
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);
194}
195
196//--------------------------------------------------------------
197void *cb_rpc_S_0400(u32 fno, void *buf, int size)
198{
199 // Rpc Callback function
200 int (*rpc_func)(void);
201
202 (void)buf;
203 (void)size;
204
205#ifdef BUILDING_XMCSERV
206 {
207 register int i;
208
209 for (i=0; i<16; i++) { // retrieve correct function number for xmcserv
210 if (fno == XMCSERV_RpcCmd[0][i]) {
211 fno = XMCSERV_RpcCmd[1][i];
212 break;
213 }
214 }
215 }
216#else
217 { // retrieve correct function number for mcserv
218 fno -= 112;
219 if (fno > 16)
220 return (void *)&rpc_stat;
221 }
222#endif
223
224 // Get function pointer
225 rpc_func = (void *)rpc_funcs_array[fno];
226
227 mcserv_in_rpc_0400 = 1;
228
229 // Call needed rpc func
230 rpc_stat.result = rpc_func();
231
232 McReplaceBadBlock();
233
234 mcserv_in_rpc_0400 = 0;
235
236 return (void *)&rpc_stat;
237}
238
239//--------------------------------------------------------------
240int sceMcInit(void)
241{
242 register int r;
243#ifdef BUILDING_XMCSERV
244 struct irx_id *ModuleInfo;
245#endif
246
247 r = _McInit(&mcserv_rpc_buf);
248
249#ifdef BUILDING_XMCSERV
250 {
251 ModuleInfo = McGetModuleInfo();
252 rpc_stat.mcserv_version = MODVER;
253 rpc_stat.mcman_version = ModuleInfo->v;
254 }
255#endif
256
257 return r;
258}
259
260//--------------------------------------------------------------
261int sceMcOpen(void)
262{
263 return _McOpen(&mcserv_rpc_buf);
264}
265
266//--------------------------------------------------------------
267int sceMcClose(void)
268{
269 return _McClose(&mcserv_rpc_buf);
270}
271
272//--------------------------------------------------------------
273int sceMcRead(void)
274{
275 return _McRead(&mcserv_rpc_buf);
276}
277
278//--------------------------------------------------------------
279int sceMcRead2(void)
280{
281 return _McRead2(&mcserv_rpc_buf);
282}
283
284//--------------------------------------------------------------
285int sceMcWrite(void)
286{
287 return _McWrite(&mcserv_rpc_buf);
288}
289
290//--------------------------------------------------------------
291int sceMcSeek(void)
292{
293 return _McSeek(&mcserv_rpc_buf);
294}
295
296//--------------------------------------------------------------
297int sceMcGetDir(void)
298{
299 return _McGetDir(&mcserv_rpc_buf);
300}
301
302//--------------------------------------------------------------
303int sceMcFormat(void)
304{
305 return _McFormat(&mcserv_rpc_buf);
306}
307
308//--------------------------------------------------------------
309int sceMcUnformat(void)
310{
311 return _McUnformat(&mcserv_rpc_buf);
312}
313
314//--------------------------------------------------------------
315int sceMcGetInfo(void)
316{
317 return _McGetInfo(&mcserv_rpc_buf);
318}
319
320//--------------------------------------------------------------
321#ifdef BUILDING_XMCSERV
322int sceMcGetInfo2(void)
323{
324 return _McGetInfo2(&mcserv_rpc_buf);
325}
326#endif
327
328//--------------------------------------------------------------
329int sceMcDelete(void)
330{
331 return _McDelete(&mcserv_rpc_buf);
332}
333
334//--------------------------------------------------------------
335int sceMcFlush(void)
336{
337 return _McFlush(&mcserv_rpc_buf);
338}
339
340//--------------------------------------------------------------
341int sceMcChDir(void)
342{
343 return _McChDir(&mcserv_rpc_buf);
344}
345
346//--------------------------------------------------------------
347int sceMcEraseBlock(void)
348{
349 return _McEraseBlock(&mcserv_rpc_buf);
350}
351
352//--------------------------------------------------------------
353int sceMcReadPage(void)
354{
355 return _McReadPage(&mcserv_rpc_buf);
356}
357
358//--------------------------------------------------------------
359int sceMcWritePage(void)
360{
361 return _McWritePage(&mcserv_rpc_buf);
362}
363
364//--------------------------------------------------------------
365int sceMcSetFileInfo(void)
366{
367 return _McSetFileInfo(&mcserv_rpc_buf);
368}
369
370//--------------------------------------------------------------
371#ifdef BUILDING_XMCSERV
372int sceMcGetEntSpace(void)
373{
374 return _McGetEntSpace(&mcserv_rpc_buf);
375}
376#endif
377
378//--------------------------------------------------------------
379#ifdef BUILDING_XMCSERV
380int sceMcCheckBlock(void)
381{
382 return _McCheckBlock(&mcserv_rpc_buf);
383}
384#endif
385
386//--------------------------------------------------------------
387int _McInit(void *rpc_buf)
388{
389 mcDescParam_t *dP = (mcDescParam_t *)rpc_buf;
390
391 DPRINTF("_McInit fd %d offset %d\n", dP->fd, dP->offset);
392
393#ifndef BUILDING_XMCSERV
394 {
395 int ps1flag = 0;
396
397 if (dP->offset == -217)
398 ps1flag = 1;
399
400 McSetPS1CardFlag(ps1flag);
401 }
402#endif
403
404 return McRetOnly(dP->fd);
405}
406
407//--------------------------------------------------------------
408int _McOpen(void *rpc_buf)
409{
410 mcNameParam_t *nP = (mcNameParam_t *)rpc_buf;
411
412 DPRINTF("_McOpen port%d slot%d file %s flags %d\n", nP->port, nP->slot, nP->name, nP->flags);
413
414 return McOpen(nP->port, nP->slot, nP->name, nP->flags);
415}
416
417//--------------------------------------------------------------
418int _McClose(void *rpc_buf)
419{
420 mcDescParam_t *dP = (mcDescParam_t *)rpc_buf;
421
422 DPRINTF("_McClose fd %d\n", dP->fd);
423
424 return McClose(dP->fd);
425}
426
427//--------------------------------------------------------------
428int _McSeek(void *rpc_buf)
429{
430 mcDescParam_t *dP = (mcDescParam_t *)rpc_buf;
431
432 DPRINTF("_McSeek fd %d offset %d origin %d\n", dP->fd, dP->offset, dP->origin);
433
434 return McSeek(dP->fd, dP->offset, dP->origin);
435}
436
437//--------------------------------------------------------------
438int _McRead(void *rpc_buf)
439{
440 mcDescParam_t *dP = (mcDescParam_t *)rpc_buf;
441 register int file_offset, status;
442 register int left_to_read, size_readed, size_to_read;
443 mcEndParam_t eP;
444 SifDmaTransfer_t dmaStruct;
445 int intStatus;
446 void *eedata;
447
448 DPRINTF("_McRead fd %d ee buffer addr %x size %d\n", dP->fd, (int)dP->buffer, dP->size);
449
450 eP.size1 = 0;
451 eP.size2 = 0;
452 eP.dest1 = NULL;
453 eP.dest2 = NULL;
454
455 size_readed = 0;
456 file_offset = 0;
457
458 eedata = dP->buffer;
459
460 eP.size1 = dP->size;
461
462 if (dP->size > 16)
463 eP.size1 = (((int)(eedata)-1) & 0xfffffff0) - ((int)(eedata) - 16);
464
465 eP.size2 = (dP->size - eP.size1) & 0x0f;
466 left_to_read = (dP->size - eP.size1) - eP.size2;
467
468 if (eP.size2 != 0)
469 eP.dest2 = (void *)((u8 *)eedata + eP.size1 + left_to_read);
470
471 if (eP.size1 != 0) {
472 size_readed = McRead(dP->fd, eP.src1, eP.size1);
473
474 if (size_readed < 0) {
475 eP.size1 = 0;
476 eP.size2 = 0;
477 goto dma_transfer2;
478 }
479 else {
480 file_offset = size_readed;
481 eP.dest1 = eedata;
482 eedata = (void *)((u8 *)eedata + size_readed);
483
484 if (size_readed != eP.size1) {
485 eP.size1 = size_readed;
486 eP.size2 = 0;
487 size_readed = 0;
488 goto dma_transfer2;
489 }
490 else
491 size_readed = 0;
492 }
493 }
494
495 while (left_to_read > 0) {
496
497 size_to_read = left_to_read;
498
499 if (left_to_read > MCSERV_BUFSIZE)
500 size_to_read = MCSERV_BUFSIZE;
501
502 size_readed = McRead(dP->fd, mcserv_buf, size_to_read);
503
504 if (size_readed < 0) {
505 eP.size2 = 0;
506 goto dma_transfer2;
507 }
508
509 dmaStruct.src = (void *)mcserv_buf;
510 dmaStruct.dest = (void *)eedata;
511 dmaStruct.size = size_readed;
512 dmaStruct.attr = 0;
513
514 CpuSuspendIntr(&intStatus);
515 sceSifSetDma(&dmaStruct, 1);
516
517 file_offset += size_readed;
518 left_to_read -= size_readed;
519
520 CpuResumeIntr(intStatus);
521
522 eedata = (void *)((u8 *)eedata + size_readed);
523
524 if (size_to_read != size_readed) {
525 eP.size2 = 0;
526 size_readed = 0;
527 goto dma_transfer2;
528 }
529 size_readed = 0;
530 }
531
532 if (eP.size2 == 0)
533 goto dma_transfer2;
534
535 size_readed = McRead(dP->fd, eP.src2, eP.size2);
536
537 if (size_readed < 0) {
538 eP.size2 = 0;
539 goto dma_transfer2;
540 }
541
542 file_offset += size_readed;
543 eP.size2 = size_readed;
544 size_readed = 0;
545
546dma_transfer2:
547 dmaStruct.src = (void *)&eP;
548 dmaStruct.dest = (void *)dP->param;
549 dmaStruct.size = sizeof (mcEndParam_t);
550 dmaStruct.attr = 0;
551
552 CpuSuspendIntr(&intStatus);
553 status = sceSifSetDma(&dmaStruct, 1);
554 CpuResumeIntr(intStatus);
555
556 while (sceSifDmaStat(status) >= 0)
557 DelayThread(100);
558
559 if (size_readed != 0)
560 return size_readed;
561
562 return file_offset;
563}
564
565//--------------------------------------------------------------
566int _McRead2(void *rpc_buf)
567{
568 mcDescParam_t *dP = (mcDescParam_t *)rpc_buf;
569 register int file_offset, status;
570 register int left_to_read, size_readed, size_to_read;
571 mcEndParam2_t eP;
572 SifDmaTransfer_t dmaStruct;
573 int intStatus;
574 void *eedata;
575
576 DPRINTF("_McRead2 fd %d ee buffer addr %x size %d\n", dP->fd, (int)dP->buffer, dP->size);
577
578 eP.size1 = 0;
579 eP.size2 = 0;
580 eP.dest1 = NULL;
581 eP.dest2 = NULL;
582
583 size_readed = 0;
584 file_offset = 0;
585
586 eedata = dP->buffer;
587
588 eP.size1 = dP->size;
589
590 if (dP->size > 64)
591 eP.size1 = (((u32)(eedata)-1) & 0xffffffc0) - ((u32)(eedata) - 64);
592
593 eP.size2 = (dP->size - eP.size1) & 0x3f;
594 left_to_read = (dP->size - eP.size1) - eP.size2;
595
596 if (eP.size2 != 0)
597 eP.dest2 = (void *)((u8 *)eedata + eP.size1 + left_to_read);
598
599 if (eP.size1 != 0) {
600 size_readed = McRead(dP->fd, eP.src1, eP.size1);
601
602 if (size_readed < 0) {
603 eP.size1 = 0;
604 eP.size2 = 0;
605 goto dma_transfer2;
606 }
607 else {
608 file_offset = size_readed;
609 eP.dest1 = eedata;
610 eedata = (void *)((u8 *)eedata + size_readed);
611
612 if (size_readed != eP.size1) {
613 eP.size1 = size_readed;
614 eP.size2 = 0;
615 size_readed = 0;
616 goto dma_transfer2;
617 }
618 else
619 size_readed = 0;
620 }
621 }
622
623 while (left_to_read > 0) {
624
625 size_to_read = left_to_read;
626
627 if (left_to_read > MCSERV_BUFSIZE)
628 size_to_read = MCSERV_BUFSIZE;
629
630 size_readed = McRead(dP->fd, mcserv_buf, size_to_read);
631
632 if (size_readed < 0) {
633 eP.size2 = 0;
634 goto dma_transfer2;
635 }
636
637 if (size_readed == size_to_read) {
638 dmaStruct.size = size_readed;
639 goto dma_transfer;
640 }
641
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);
646 }
647
648 if (eP.size2 == size_readed)
649 goto skip_dma_transfer;
650
651 dmaStruct.size = size_readed - eP.size2;
652
653dma_transfer:
654 dmaStruct.src = (void *)mcserv_buf;
655 dmaStruct.dest = (void *)eedata;
656 dmaStruct.attr = 0;
657
658 CpuSuspendIntr(&intStatus);
659 sceSifSetDma(&dmaStruct, 1);
660 CpuResumeIntr(intStatus);
661
662skip_dma_transfer:
663 file_offset += size_readed;
664 left_to_read -= size_readed;
665 eedata = (void *)((u8 *)eedata + size_readed);
666
667 if (size_to_read != size_readed) {
668 size_readed = 0;
669 goto dma_transfer2;
670 }
671 size_readed = 0;
672 }
673
674 if (eP.size2 == 0)
675 goto dma_transfer2;
676
677 size_readed = McRead(dP->fd, eP.src2, eP.size2);
678
679 if (size_readed < 0) {
680 eP.size2 = 0;
681 goto dma_transfer2;
682 }
683
684 file_offset += size_readed;
685 eP.size2 = size_readed;
686 size_readed = 0;
687
688dma_transfer2:
689 dmaStruct.src = (void *)&eP;
690 dmaStruct.dest = (void *)dP->param;
691 dmaStruct.size = sizeof (mcEndParam2_t);
692 dmaStruct.attr = 0;
693
694 CpuSuspendIntr(&intStatus);
695 status = sceSifSetDma(&dmaStruct, 1);
696 CpuResumeIntr(intStatus);
697
698 while (sceSifDmaStat(status) >= 0)
699 DelayThread(100);
700
701 if (size_readed != 0)
702 return size_readed;
703
704 return file_offset;
705}
706
707//--------------------------------------------------------------
708int _McWrite(void *rpc_buf)
709{
710 mcDescParam_t *dP = (mcDescParam_t *)rpc_buf;
712 register int size_written;
713
714 DPRINTF("_McWrite fd %d ee buffer addr %x size %d\n", dP->fd, (int)dP->buffer, dP->size);
715
716 size_written = 0;
717
718 if (dP->origin != 0) {
719 size_written = McWrite(dP->fd, dP->data, dP->origin);
720
721 if (size_written != dP->origin)
722 return size_written;
723 }
724
725 while (dP->size > 0) {
726 register int size_to_write, r;
727
728 size_to_write = dP->size;
729
730 if (dP->size > MCSERV_BUFSIZE)
731 size_to_write = MCSERV_BUFSIZE;
732
733 sceSifGetOtherData(&rD, dP->buffer, &mcserv_buf, size_to_write, 0);
734
735 r = McWrite(dP->fd, &mcserv_buf, size_to_write);
736 if (r != size_to_write) {
737 if (r < 0)
738 return r;
739 return r + size_written;
740 }
741
742 size_written += size_to_write;
743 dP->size -= size_to_write;
744
745 dP->buffer += size_to_write;
746 }
747
748 return size_written;
749}
750
751//--------------------------------------------------------------
752int _McGetDir(void *rpc_buf)
753{
754 mcNameParam_t *nP = (mcNameParam_t *)rpc_buf;
755 register int status, file_entries, flags, r;
756 SifDmaTransfer_t dmaStruct;
757 int intStatus;
758
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);
760
761 status = 0;
762 file_entries = 0;
763 flags = nP->flags;
764
765 nP->maxent--;
766
767 while (nP->maxent > -1) {
768
769 r = McGetDir(nP->port, nP->slot, nP->name, flags & 0xffff, 1, (sceMcTblGetDir *)mcserv_buf);
770 if (r < 0)
771 return r;
772 if (r == 0)
773 goto dma_wait;
774
775 file_entries++;
776
777 dmaStruct.src = (void *)mcserv_buf;
778 dmaStruct.dest = (void *)nP->mcT;
779 dmaStruct.size = sizeof (sceMcTblGetDir);
780 dmaStruct.attr = 0;
781
782 CpuSuspendIntr(&intStatus);
783 status = sceSifSetDma(&dmaStruct, 1);
784 CpuResumeIntr(intStatus);
785
786 flags = 1;
787 nP->mcT++;
788 nP->maxent--;
789 }
790
791dma_wait:
792 if (status == 0)
793 return file_entries;
794
795 while (sceSifDmaStat(status) >= 0)
796 DelayThread(100);
797
798 return file_entries;
799}
800
801//--------------------------------------------------------------
802int _McChDir(void *rpc_buf)
803{
804 mcNameParam_t *nP = (mcNameParam_t *)rpc_buf;
805 register int status, r;
806 SifDmaTransfer_t dmaStruct;
807 int intStatus;
808
809 DPRINTF("_McChDir port%d slot%d newdir %s\n", nP->port, nP->slot, nP->name);
810
811 r = McChDir(nP->port, nP->slot, nP->name, (char *)mcserv_buf);
812
813 dmaStruct.src = (void *)mcserv_buf;
814 dmaStruct.dest = (void *)nP->curdir;
815 dmaStruct.size = 1024;
816 dmaStruct.attr = 0;
817
818 CpuSuspendIntr(&intStatus);
819 status = sceSifSetDma(&dmaStruct, 1);
820 CpuResumeIntr(intStatus);
821
822 while (sceSifDmaStat(status) >= 0)
823 DelayThread(100);
824
825 return r;
826}
827
828//--------------------------------------------------------------
829int _McFormat(void *rpc_buf)
830{
831 mcDescParam_t *dP = (mcDescParam_t *)rpc_buf;
832
833 DPRINTF("_McFormat port%d slot%d\n", dP->port, dP->slot);
834
835 return McFormat(dP->port, dP->slot);
836}
837
838//--------------------------------------------------------------
839int _McUnformat(void *rpc_buf)
840{
841 mcDescParam_t *dP = (mcDescParam_t *)rpc_buf;
842
843 DPRINTF("_McUnformat port%d slot%d\n", dP->port, dP->slot);
844
845 return McUnformat(dP->port, dP->slot);
846}
847
848//--------------------------------------------------------------
849int _McGetInfo(void *rpc_buf)
850{
851 mcDescParam_t *dP = (mcDescParam_t *)rpc_buf;
852 register int status, mc_free, r;
853 mcEndParam_t eP;
854 SifDmaTransfer_t dmaStruct;
855 int intStatus;
856
857 DPRINTF("_McGetInfo port%d slot%d\n", dP->port, dP->slot);
858
859 mc_free = 0;
860
861 r = McDetectCard(dP->port, dP->slot);
862
863 if (dP->size > 0)
864 eP.type = McGetMcType(dP->port, dP->slot);
865
866 eP.free = 0;
867 if (r >= -1) {
868 if (dP->offset == 0)
869 goto dma_transfer;
870
871 mc_free = McGetFreeClusters(dP->port, dP->slot);
872 if (mc_free >= 0)
873 eP.free = mc_free;
874 }
875
876dma_transfer:
877
878 dmaStruct.src = (void *)&eP;
879 dmaStruct.dest = (void *)dP->param;
880 dmaStruct.size = sizeof (mcEndParam_t);
881 dmaStruct.attr = 0;
882
883 CpuSuspendIntr(&intStatus);
884 status = sceSifSetDma(&dmaStruct, 1);
885 CpuResumeIntr(intStatus);
886
887 while (sceSifDmaStat(status) >= 0)
888 DelayThread(100);
889
890 if (mc_free < 0)
891 return mc_free;
892
893 return r;
894}
895
896//--------------------------------------------------------------
897#ifdef BUILDING_XMCSERV
898int _McGetInfo2(void *rpc_buf)
899{
900 mcDescParam_t *dP = (mcDescParam_t *)rpc_buf;
901 register int status, mc_free, r;
902 mcEndParam2_t eP;
903 SifDmaTransfer_t dmaStruct;
904 int intStatus;
905
906 DPRINTF("_McGetInfo2 port%d slot%d\n", dP->port, dP->slot);
907
908 mc_free = 0;
909
910 r = McDetectCard2(dP->port, dP->slot);
911
912 if (dP->origin > 0)
913 eP.type = McGetMcType(dP->port, dP->slot);
914
915 if (r < -1) {
916 eP.free = 0;
917 eP.formatted = 0;
918 goto dma_transfer;
919 }
920
921 if (dP->offset > 0) {
922 mc_free = McGetFreeClusters(dP->port, dP->slot);
923
924 if (mc_free < 0)
925 eP.free = 0;
926 else
927 eP.free = mc_free;
928 }
929
930 if (dP->size > 0) {
931 eP.formatted = 0;
932 if (McGetFormat(dP->port, dP->slot) > 0)
933 eP.formatted = 1;
934 }
935
936dma_transfer:
937
938 dmaStruct.src = (void *)&eP;
939 dmaStruct.dest = (void *)dP->param;
940 dmaStruct.size = sizeof (mcEndParam2_t);
941 dmaStruct.attr = 0;
942
943 CpuSuspendIntr(&intStatus);
944 status = sceSifSetDma(&dmaStruct, 1);
945 CpuResumeIntr(intStatus);
946
947 while (sceSifDmaStat(status) >= 0)
948 DelayThread(100);
949
950 if (mc_free < 0)
951 return mc_free;
952
953 return r;
954}
955#endif
956
957//--------------------------------------------------------------
958#ifdef BUILDING_XMCSERV
959int _McGetEntSpace(void *rpc_buf)
960{
961 mcNameParam_t *nP = (mcNameParam_t *)rpc_buf;
962
963 DPRINTF("_McGetEntSpace port%d slot%d dirname %s\n", nP->port, nP->slot, nP->name);
964
965 return McGetEntSpace(nP->port, nP->slot, nP->name);
966}
967#endif
968
969//--------------------------------------------------------------
970int _McDelete(void *rpc_buf)
971{
972 mcNameParam_t *nP = (mcNameParam_t *)rpc_buf;
973
974 DPRINTF("_McDelete port%d slot%d file %s flags %d\n", nP->port, nP->slot, nP->name, nP->flags);
975
976 return McDelete(nP->port, nP->slot, nP->name, nP->flags);
977}
978
979//--------------------------------------------------------------
980int _McFlush(void *rpc_buf)
981{
982 mcDescParam_t *dP = (mcDescParam_t *)rpc_buf;
983
984 DPRINTF("_McFlush fd %d\n", dP->fd);
985
986 return McFlush(dP->fd);
987}
988
989//--------------------------------------------------------------
990int _McEraseBlock(void *rpc_buf)
991{
992 mcDescParam_t *dP = (mcDescParam_t *)rpc_buf;
993 register int r;
994 u8 eccbuf[16];
995
996 DPRINTF("_McEraseBlock port%d slot%d offset %d\n", dP->port, dP->slot, dP->offset);
997
998 dP->port = (dP->port & 1) + 2;
999
1000 if (McGetMcType(dP->port, dP->slot) == 2) {
1001 register int pagenum;
1002
1003 r = McEraseBlock(dP->port, dP->offset, NULL, NULL);
1004 if (r != 0)
1005 return r;
1006
1007 if (dP->origin == -1)
1008 return r;
1009
1010 memset(mcserv_buf, dP->origin, 512);
1011
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]);
1016
1017 pagenum = 0;
1018
1019 do {
1020 r = McWritePage(dP->port, dP->slot, (dP->offset << 4) + pagenum, mcserv_buf, eccbuf);
1021
1022 } while (++pagenum < 16); // <-- and the last page of the block ???
1023
1024 return r;
1025
1026 }
1027
1028 memset(mcserv_buf, dP->origin, 128);
1029
1030 r = McWritePS1PDACard(dP->port, dP->slot, dP->offset, mcserv_buf);
1031
1032 return r;
1033}
1034
1035//--------------------------------------------------------------
1036int _McReadPage(void *rpc_buf)
1037{
1038 mcDescParam_t *dP = (mcDescParam_t *)rpc_buf;
1039 mcEndParam_t eP;
1040 register int status, fastsize, r, i, j;
1041 SifDmaTransfer_t dmaStruct;
1042 int intStatus;
1043
1044 DPRINTF("_McReadPage port%d slot%d page %d\n", dP->port, dP->slot, dP->fd);
1045
1046 eP.dest1 = dP->buffer;
1047
1048 fastsize = ((u32)dP->buffer) & 0xf;
1049 dP->port = (dP->port & 1) + 2;
1050
1051 if (McGetMcType(dP->port, dP->slot) == 2) {
1052 r = 0;
1053 McReadPage(dP->port, dP->slot, dP->fd, (void *)(mcserv_buf + fastsize));
1054 }
1055 else {
1056 memset((void *)(mcserv_buf + fastsize), 0, 512);
1057 r = McReadPS1PDACard(dP->port, dP->slot, dP->fd, (void *)(mcserv_buf + fastsize));
1058 }
1059
1060 if (fastsize == 0)
1061 goto fullpage;
1062
1063 i = 0;
1064 j = fastsize;
1065 while (j < 16) {
1066 eP.src1[i] = mcserv_buf[j];
1067 j++;
1068 i++;
1069 }
1070
1071 j = 0;
1072 if (fastsize > 0) {
1073 while (j < 16) {
1074 eP.src1[i] = mcserv_buf[512 + j];
1075 j++;
1076 i++;
1077 }
1078 }
1079
1080 dmaStruct.src = (void *)(mcserv_buf + 16);
1081 dmaStruct.dest = (void *)(dP->buffer - (fastsize - 16));
1082 dmaStruct.size = 496;
1083 dmaStruct.attr = 0;
1084 goto dma_transfer;
1085
1086fullpage:
1087 dmaStruct.src = (void *)mcserv_buf;
1088 dmaStruct.dest = (void *)dP->buffer;
1089 dmaStruct.size = 512;
1090 dmaStruct.attr = 0;
1091
1092dma_transfer:
1093 CpuSuspendIntr(&intStatus);
1094 sceSifSetDma(&dmaStruct, 1);
1095 CpuResumeIntr(intStatus);
1096
1097 dmaStruct.src = (void *)&eP;
1098 dmaStruct.dest = (void *)dP->param;
1099 dmaStruct.size = sizeof (mcEndParam_t);
1100 dmaStruct.attr = 0;
1101
1102 CpuSuspendIntr(&intStatus);
1103 status = sceSifSetDma(&dmaStruct, 1);
1104 CpuResumeIntr(intStatus);
1105
1106 while (sceSifDmaStat(status) >= 0)
1107 DelayThread(100);
1108
1109 return r;
1110}
1111
1112//--------------------------------------------------------------
1113int _McWritePage(void *rpc_buf)
1114{
1115 mcDescParam_t *dP = (mcDescParam_t *)rpc_buf;
1116 register int fastsize, i, j;
1118 u8 eccbuf[16];
1119
1120 DPRINTF("_McWritePage port%d slot%d page %d\n", dP->port, dP->slot, dP->fd);
1121
1122 fastsize = ((u32)dP->buffer) & 0xf;
1123 if (fastsize == 0)
1124 goto fullpage;
1125
1126 sceSifGetOtherData(&rD, (void *)(dP->buffer - (fastsize - 16)), &mcserv_buf, 496, 0);
1127
1128 i = fastsize;
1129 while (i < 16) {
1130 mcserv_buf[i] = dP->data[i - fastsize];
1131 i++;
1132 }
1133
1134 if (fastsize == 0)
1135 goto ecc_calc;
1136
1137
1138 j = 16;
1139 i = 0;
1140 while (i < fastsize) {
1141 mcserv_buf[496 + j] = dP->data[j - fastsize];
1142 i++;
1143 j++;
1144 }
1145
1146 goto ecc_calc;
1147
1148fullpage:
1149
1150 sceSifGetOtherData(&rD, dP->buffer, &mcserv_buf, 512, 0);
1151
1152ecc_calc:
1153
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]);
1158
1159 return McWritePage((dP->port & 1) | 2, dP->slot, dP->fd, (void *)(mcserv_buf + fastsize), eccbuf);
1160}
1161
1162//--------------------------------------------------------------
1163int _McSetFileInfo(void *rpc_buf)
1164{
1165 mcNameParam_t *nP = (mcNameParam_t *)rpc_buf;
1167
1168 DPRINTF("_McSetFileInfo port%d slot%d file %s flags %d\n", nP->port, nP->slot, nP->name, nP->flags);
1169
1170 sceSifGetOtherData(&rD, (void *)nP->mcT, &mcserv_buf, sizeof (sceMcTblGetDir), 0);
1171
1172 return McSetFileInfo(nP->port, nP->slot, nP->name, (sceMcTblGetDir *)mcserv_buf, nP->flags);
1173}
1174
1175//--------------------------------------------------------------
1176#ifdef BUILDING_XMCSERV
1177int _McCheckBlock(void *rpc_buf)
1178{
1179 mcDescParam_t *dP = (mcDescParam_t *)rpc_buf;
1180
1181 DPRINTF("_McCheckBlock port%d slot%d block %d\n", dP->port, dP->slot, dP->offset);
1182
1183 return McCheckBlock(dP->port, dP->slot, dP->offset);
1184}
1185#endif
1186
1187//--------------------------------------------------------------
int CpuEnableIntr()
Definition intrman.c:250
int CpuResumeIntr(int state)
Definition intrman.c:227
int CpuSuspendIntr(int *state)
Definition intrman.c:205
Definition irx.h:27
u16 newflags
Definition loadcore.h:36