ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
sior_rpc.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
16 #include <tamtypes.h>
17 #include <kernel.h>
18 #include <sifrpc.h>
19 #include <stdarg.h>
20 #include <string.h>
21 #include <malloc.h>
22 #include <fcntl.h>
23 #include <stdio.h>
24 #include <sio.h>
25 #include "sior_rpc.h"
26 
27 static SifRpcDataQueue_t qd __attribute__((aligned(64)));
28 static SifRpcServerData_t Sd0 __attribute__((aligned(64)));
29 static u32 buffer[32] __attribute__((aligned(64)));
30 
32 #define IOP_MEM 0xbc000000
33 
34 enum {
35  SIOR_INIT = 1,
45 };
46 
53 };
54 
55 static void * sior_rpc_server(u32 funcno, void * data, int size) {
56  int res = 0, c;
57  size_t s;
58  char * p;
59  struct init_arguments_t * i;
60  switch(funcno) {
61  case SIOR_INIT:
62  i = (struct init_arguments_t *) data;
64  break;
65  case SIOR_PUTC:
66  c = *((int *) data);
67  res = sio_putc(c);
68  break;
69  case SIOR_GETC:
70  res = sio_getc();
71  break;
72  case SIOR_GETCBLOCK:
73  res = sio_getc_block();
74  break;
75  case SIOR_WRITE:
76  p = *((char **) data) + IOP_MEM;
77  s = *(((size_t *) data) + 1);
78  DI();
80  res = sio_write(p, s);
81  ee_kmode_exit();
82  EI();
83  break;
84  case SIOR_READ:
85  p = *((char **) data) + IOP_MEM;
86  s = *(((size_t *) data) + 1);
87  DI();
89  res = sio_read(p, s);
90  ee_kmode_exit();
91  EI();
92  break;
93  case SIOR_PUTS:
94  p = *((char **) data) + IOP_MEM;
95  DI();
97  res = sio_puts(p);
98  ee_kmode_exit();
99  EI();
100  break;
101  case SIOR_PUTSN:
102  p = *((char **) data) + IOP_MEM;
103  DI();
104  ee_kmode_enter();
105  res = sio_putsn(p);
106  ee_kmode_exit();
107  EI();
108  break;
109  case SIOR_GETS:
110  p = *((char **) data) + IOP_MEM;
111  DI();
112  ee_kmode_enter();
113  res = (int)sio_gets(p);
114  ee_kmode_exit();
115  EI();
116  break;
117  case SIOR_FLUSH:
118  sio_flush();
119  break;
120  }
121 
122  *((int *) data) = res;
123 
124  return data;
125 }
126 
127 static void sior_thread(void) {
128  SifInitRpc(0);
131  SifRpcLoop(&qd);
132 }
133 
134 int SIOR_Init(int priority)
135 {
136  static int sior_init_done = 0;
137  static u8 stack[4096];
138  int thid;
139  ee_thread_t t;
140 
141  if (sior_init_done)
142  return 0;
143 
144  t.func = sior_thread;
145  t.gp_reg = 0;
146  t.initial_priority = priority;
147  t.stack = stack;
148  t.stack_size = 4096;
149  if ((thid = CreateThread(&t)) < 0) {
150  printf("Error creating SIO Remote EE-thread.\n");
151  return thid;
152  }
153  StartThread(thid, NULL);
154 
155  sior_init_done = 1;
156  return thid;
157 }
static int ee_kmode_exit()
Definition: kernel.h:198
s32 CreateThread(ee_thread_t *thread)
static int ee_kmode_enter()
Definition: kernel.h:181
s32 StartThread(s32 thread_id, void *args)
#define DI
Definition: kernel.h:24
#define EI
Definition: kernel.h:25
s32 GetThreadId(void)
u32 data
Definition: libmouse.c:36
s32 s
Definition: ps2ipc.c:30
void SifInitRpc(int mode)
SifRpcServerData_t * SifRegisterRpc(SifRpcServerData_t *srv, int sid, SifRpcFunc_t func, void *buff, SifRpcFunc_t cfunc, void *cbuff, SifRpcDataQueue_t *qd)
SifRpcDataQueue_t * SifSetRpcQueue(SifRpcDataQueue_t *q, int thread_id)
void SifRpcLoop(SifRpcDataQueue_t *q)
void *(* SifRpcFunc_t)(int fno, void *buffer, int length)
Definition: sifrpc.h:32
int sio_putsn(const char *str)
int sio_putc(int c)
char * sio_gets(char *str)
void sio_flush(void)
int sio_puts(const char *str)
int sio_getc(void)
void sio_init(u32 baudrate, u8 lcr_ueps, u8 lcr_upen, u8 lcr_usbl, u8 lcr_umode)
int sio_getc_block(void)
size_t sio_read(void *buf, size_t size)
size_t sio_write(void *buf, size_t size)
static SifRpcServerData_t Sd0
Definition: sior_rpc.c:28
@ SIOR_INIT
Definition: sior_rpc.c:35
@ SIOR_PUTS
Definition: sior_rpc.c:41
@ SIOR_WRITE
Definition: sior_rpc.c:39
@ SIOR_GETC
Definition: sior_rpc.c:37
@ SIOR_FLUSH
Definition: sior_rpc.c:44
@ SIOR_READ
Definition: sior_rpc.c:40
@ SIOR_GETCBLOCK
Definition: sior_rpc.c:38
@ SIOR_PUTSN
Definition: sior_rpc.c:42
@ SIOR_PUTC
Definition: sior_rpc.c:36
@ SIOR_GETS
Definition: sior_rpc.c:43
#define IOP_MEM
Definition: sior_rpc.c:32
static void * sior_rpc_server(u32 funcno, void *data, int size)
Definition: sior_rpc.c:55
static SifRpcDataQueue_t qd
Definition: sior_rpc.c:27
static void sior_thread(void)
Definition: sior_rpc.c:127
int SIOR_Init(int priority)
Definition: sior_rpc.c:134
static u32 buffer[32]
Definition: sior_rpc.c:29
#define SIOR_IRX
Definition: sior_rpc.h:19
void * gp_reg
Definition: kernel.h:230
int stack_size
Definition: kernel.h:229
void * func
Definition: kernel.h:227
void * stack
Definition: kernel.h:228
int initial_priority
Definition: kernel.h:231
#define NULL
Definition: tamtypes.h:91
unsigned int u32
Definition: tamtypes.h:30
unsigned char u8
Definition: tamtypes.h:23