11#include "irx_imports.h"
14#define MODNAME "FILEIO_service"
23#define DPRINTF(x...) printf(MODNAME ": " x)
30static void *xfer_buffer;
34static void fileio_rpc_start_thread(
void *param);
35static void heap_rpc_start_thread(
void *param);
37int _start(
int argc,
char *argv[])
40 int fileio_rpc_thread;
45 BootMode = QueryBootMode(3);
49 iop_boot_param = BootMode[1];
50 if ((iop_boot_param & 1) != 0) {
51 DPRINTF(
" No SIF service(fileio)\n");
52 return MODULE_NO_RESIDENT_END;
54 if ((iop_boot_param & 2) != 0) {
55 DPRINTF(
" No FILEIO service\n");
56 return MODULE_NO_RESIDENT_END;
60 thread_param.thread = fileio_rpc_start_thread;
61 thread_param.attr = 0x2000000;
62 thread_param.priority = 96;
63 thread_param.stacksize = 4096;
64 thread_param.option = 0;
65 fileio_rpc_thread = CreateThread(&thread_param);
66 if (fileio_rpc_thread <= 0) {
67 return MODULE_NO_RESIDENT_END;
69 StartThread(fileio_rpc_thread, 0);
70 thread_param.thread = heap_rpc_start_thread;
71 thread_param.attr = 0x2000000;
72 thread_param.priority = 96;
73 thread_param.stacksize = 2048;
74 thread_param.option = 0;
75 heap_rpc_thread = CreateThread(&thread_param);
76 if (heap_rpc_thread <= 0) {
77 return MODULE_NO_RESIDENT_END;
79 StartThread(heap_rpc_thread, 0);
80 return MODULE_RESIDENT_END;
83static void *fileio_allocate_buffer_memory()
90 xfer_buffer = AllocSysMemory(1, xfer_size, 0);
100 DPRINTF(
"read/write allocate memory %x\n", xfer_size);
104static void fileio_rpc_open(
struct _fio_open_arg *buffer,
int length,
int *outbuffer)
106 if ((xfer_buffer != NULL) || ((xfer_buffer = fileio_allocate_buffer_memory()) != NULL)) {
109 DPRINTF(
"open name %s flag %x data %x\n", buffer->name, buffer->mode, (u32)(buffer));
110 fd = io_open(buffer->name, buffer->mode);
111 DPRINTF(
"open fd = %d\n", fd);
114 DPRINTF(
"Error:Cannot alloc r/w buffer\n");
119static void fileio_rpc_close(
int *buffer,
int length,
int *outbuffer)
121 *outbuffer = io_close(*buffer);
124static void fileio_rpc_lseek(
struct _fio_lseek_arg *buffer,
int length,
int *outbuffer)
126 *outbuffer = io_lseek(buffer->p.fd, buffer->offset, buffer->whence);
129static void fileio_rpc_read(
struct _fio_read_arg *buffer,
int length,
int *outbuffer)
153 ptr = (
unsigned int)buffer->ptr;
157 if ((ptr & 0x3F) != 0) {
158 v7 = (ptr >> 6 << 6) - (ptr - 64);
163 v8 = (
char *)(ptr + v7);
164 v9 = ((ptr + size) >> 6 << 6) - (ptr + v7);
165 v10 = ptr + size - ((ptr + size) >> 6 << 6);
166 v22 = (ptr + size) >> 6 << 6;
170 if ((ptr & 0xF) != 0) {
171 v7 = (ptr >> 4 << 4) - (ptr - 16);
176 v8 = (
char *)(ptr + v7);
177 v9 = ((ptr + size) >> 4 << 4) - (ptr + v7);
178 v10 = ptr + size - ((ptr + size) >> 4 << 4);
179 v22 = (
void *)((ptr + size) >> 4 << 4);
193 v12 = io_read(fd, read_data_out.buf1, v7);
207 v16 = io_read(fd, read_data_out.buf2, v10);
221 while (sceSifDmaStat(v11) >= 0)
223 v14 = io_read(fd, xfer_buffer, v13);
234 v19.src = xfer_buffer;
236 v11 = sceSifSetDma(&v19, 1);
246 v19.src = xfer_buffer;
248 sceSifSetDma(&v19, 1);
254 read_data_out.size1 = v7;
255 read_data_out.size2 = v10;
256 read_data_out.dest1 = v21;
257 read_data_out.dest2 = v22;
258 v19.src = &read_data_out;
259 read_data = buffer->read_data;
266 v19.dest = read_data;
268 sceSifSetDma(&v19, 1);
273static void fileio_rpc_write(
struct _fio_write_arg *buffer,
int length,
int *outbuffer)
285 xfer_buffer = fileio_allocate_buffer_memory();
287 Kprintf(
"Error:Cannot alloc r/w buffer\n");
299 v9 = io_write(fd, buffer->aligned, mis);
310 v11 = (
char *)buffer->ptr + mis;
319 if (xfer_size < v10) {
322 sceSifGetOtherData(&v14, v11, xfer_buffer, v12, 0);
323 v13 = io_write(fd, xfer_buffer, v12);
341static void fileio_rpc_ioctl(
struct _fio_ioctl_arg *buffer,
int length,
int *outbuffer)
343 *outbuffer = io_ioctl(buffer->p.fd, buffer->request, buffer->data);
346static void fileio_rpc_remove(
const char *buffer,
int length,
int *outbuffer)
348 DPRINTF(
"remove file %s \n", buffer);
349 *outbuffer = io_remove(buffer);
352static void fileio_rpc_mkdir(
const char *buffer,
int length,
int *outbuffer)
354 DPRINTF(
"mkdir name %s \n", buffer);
355 *outbuffer = io_mkdir(buffer);
358static void fileio_rpc_rmdir(
const char *buffer,
int length,
int *outbuffer)
360 DPRINTF(
"rmdir name %s \n", buffer);
361 *outbuffer = io_rmdir(buffer);
364static void fileio_rpc_format(
const char *buffer,
int length,
int *outbuffer)
366 DPRINTF(
"format name %s \n", buffer);
367 *outbuffer = io_format(buffer);
370static void fileio_rpc_adddrv(
iop_io_device_t **buffer,
int length,
int *outbuffer)
372 DPRINTF(
"adddrv device addr %x\n", *buffer);
373 *outbuffer = io_AddDrv(*buffer);
376static void fileio_rpc_deldrv(
const char *buffer,
int length,
int *outbuffer)
378 DPRINTF(
"deldrv device name %s \n", buffer);
379 *outbuffer = io_DelDrv(buffer);
382static void fileio_rpc_dopen(
const char *buffer,
int length,
int *outbuffer)
386 DPRINTF(
"dopen name %s \n", buffer);
388 fd = io_dopen(buffer, 0);
389 DPRINTF(
"dopen fd = %d\n", fd);
393static void fileio_rpc_dclose(
int *buffer,
int length,
int *outbuffer)
395 *outbuffer = io_dclose(*buffer);
398static void fileio_rpc_dread(
struct _fio_dread_arg *buffer,
int length,
int *outbuffer)
403 v6 = io_dread(buffer->p.fd, (
io_dirent_t *)fileio_rpc_tmpbuf);
405 v8.src = fileio_rpc_tmpbuf;
408 v8.dest = (
void *)buffer->buf;
409 if (!sceSifSetDma(&v8, 1)) {
416static void fileio_rpc_getstat(
struct _fio_getstat_arg *buffer,
int length,
int *outbuffer)
421 v6 = io_getstat(buffer->name, (
io_stat_t *)fileio_rpc_tmpbuf);
423 v8.src = fileio_rpc_tmpbuf;
426 v8.dest = (
void *)buffer->p.result;
427 if (!sceSifSetDma(&v8, 1)) {
434static void fileio_rpc_chstat(
struct _fio_chstat_arg *buffer,
int length,
int *outbuffer)
436 *outbuffer = io_chstat(buffer->name, &buffer->stat, buffer->p.cbit);
441static int *fileio_rpc_service_handler(
int fno,
void *buffer,
int length)
445 fileio_rpc_open((
struct _fio_open_arg *)buffer, length, fileio_rpc_outbuf);
448 fileio_rpc_close((
int *)buffer, length, fileio_rpc_outbuf);
451 fileio_rpc_read((
struct _fio_read_arg *)buffer, length, fileio_rpc_outbuf);
454 fileio_rpc_write((
struct _fio_write_arg *)buffer, length, fileio_rpc_outbuf);
457 fileio_rpc_lseek((
struct _fio_lseek_arg *)buffer, length, fileio_rpc_outbuf);
460 fileio_rpc_ioctl((
struct _fio_ioctl_arg *)buffer, length, fileio_rpc_outbuf);
463 fileio_rpc_remove((
const char *)buffer, length, fileio_rpc_outbuf);
467 fileio_rpc_mkdir((
const char *)buffer, length, fileio_rpc_outbuf);
470 fileio_rpc_rmdir((
const char *)buffer, length, fileio_rpc_outbuf);
473 fileio_rpc_dopen((
const char *)buffer, length, fileio_rpc_outbuf);
476 fileio_rpc_dclose((
int *)buffer, length, fileio_rpc_outbuf);
479 fileio_rpc_dread((
struct _fio_dread_arg *)buffer, length, fileio_rpc_outbuf);
482 fileio_rpc_getstat((
struct _fio_getstat_arg *)buffer, length, fileio_rpc_outbuf);
485 fileio_rpc_chstat((
struct _fio_chstat_arg *)buffer, length, fileio_rpc_outbuf);
488 fileio_rpc_format((
const char *)buffer, length, fileio_rpc_outbuf);
491 fileio_rpc_adddrv((
iop_io_device_t **)buffer, length, fileio_rpc_outbuf);
494 fileio_rpc_deldrv((
const char *)buffer, length, fileio_rpc_outbuf);
497 DPRINTF(
"sce_fileio: unrecognized code %x\n", fno);
500 return fileio_rpc_outbuf;
507static void fileio_rpc_start_thread(
void *param)
511 if (!sceSifCheckInit())
513 DPRINTF(
"Multi Threaded Fileio module.(99/11/15) \n");
516 sceSifSetRpcQueue(&fileio_rpc_service_queue, GetThreadId());
518 &fileio_rpc_service_data,
520 (SifRpcFunc_t)fileio_rpc_service_handler,
521 fileio_rpc_service_in_buf,
524 &fileio_rpc_service_queue);
525 sceSifRpcLoop(&fileio_rpc_service_queue);
528static void heap_rpc_load_iop_heap(
struct _iop_load_heap_arg *buffer,
int length,
int *outbuffer)
532 fd = io_open(buffer->path, 1);
536 saved_pos = io_lseek(fd, 0, 2);
538 io_read(fd, buffer->p.addr, saved_pos);
542 DPRINTF(
"load heap :error \n");
547static void heap_rpc_alloc_iop_heap(
int *buffer,
int length,
int *outbuffer)
549 *outbuffer = (int)AllocSysMemory(0, *buffer, 0);
552static void heap_rpc_free_iop_heap(
void **buffer,
int length,
int *outbuffer)
554 *outbuffer = FreeSysMemory(*buffer);
559static int *heap_rpc_service_handler(
int fno,
void *buffer,
int length)
563 heap_rpc_alloc_iop_heap((
int *)buffer, length, heap_rpc_outbuf);
566 heap_rpc_free_iop_heap((
void **)buffer, length, heap_rpc_outbuf);
572 DPRINTF(
"sce_iopmem: unrecognized code %x\n", fno);
575 return heap_rpc_outbuf;
582static void heap_rpc_start_thread(
void *param)
586 if (!sceSifCheckInit())
588 DPRINTF(
"iop heap service (99/11/03)\n");
590 sceSifSetRpcQueue(&heap_rpc_service_queue, GetThreadId());
592 &heap_rpc_service_data,
594 (SifRpcFunc_t)heap_rpc_service_handler,
595 heap_rpc_service_in_buf,
598 &heap_rpc_service_queue);
599 sceSifRpcLoop(&heap_rpc_service_queue);
604static void iopinfo_rpc_querybootmode(
void *buffer,
int length,
int *outbuffer)
608 BootMode = QueryBootMode(6);
609 *outbuffer = (BootMode != 0) ? (*(u16 *)BootMode & 0xFFFC) : 0x800;
614static int *iopinfo_rpc_service_handler(
int fno,
void *buffer,
int length)
618 iopinfo_rpc_querybootmode(buffer, length, iopinfo_rpc_outbuf);
621 DPRINTF(
"sce_iopinfo: unrecognized code %x\n", fno);
624 return iopinfo_rpc_outbuf;
631static void iopinfo_rpc_service_start_thread(
void *param)
635 if (!sceSifCheckInit())
637 DPRINTF(
"iop infomation service (00/02/29)\n");
639 sceSifSetRpcQueue(&iopinfo_rpc_service_queue, GetThreadId());
641 &iopinfo_rpc_service_data,
643 (SifRpcFunc_t)iopinfo_rpc_service_handler,
644 iopinfo_rpc_service_in_buf,
647 &iopinfo_rpc_service_queue);
648 sceSifRpcLoop(&iopinfo_rpc_service_queue);
int CpuResumeIntr(int state)
int CpuSuspendIntr(int *state)