ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
iopheap.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # (C)2002, Vzzrzzn
7 # (c) 2003 Marcus R. Brown (mrbrown@0xd6.org)
8 # Licenced under Academic Free License version 2.0
9 # Review ps2sdk README & LICENSE files for further details.
10 */
11 
12 #include "tamtypes.h"
13 #include "ps2lib_err.h"
14 #include "kernel.h"
15 #include "sifrpc.h"
16 #include "sifcmd.h"
17 #include "string.h"
18 
19 #include "iopheap.h"
20 
21 #define IH_C_BOUND 0x0001
22 
23 extern int _iop_reboot_count;
25 extern int _ih_caps;
26 
27 #ifdef F_SifInitIopHeap
29 int _ih_caps = 0;
30 
31 int SifInitIopHeap()
32 {
33  int res;
34 
35  static int _rb_count = 0;
36  if(_rb_count != _iop_reboot_count)
37  {
38  _rb_count = _iop_reboot_count;
39  memset(&_ih_cd, 0, sizeof _ih_cd);
40  _ih_caps = 0;
41  memset(&_ih_caps, 0, sizeof _ih_caps);
42  }
43 
44  if (_ih_caps)
45  return 0;
46 
47  SifInitRpc(0);
48 
49  while ((res = SifBindRpc(&_ih_cd, 0x80000003, 0)) >= 0 && !_ih_cd.server)
50  nopdelay();
51 
52  if (res < 0)
53  return -E_SIF_RPC_BIND;
54 
56 
57  return 0;
58 }
59 #endif
60 
61 #ifdef F_SifExitIopHeap
62 void SifExitIopHeap()
63 {
64  _ih_caps = 0;
65  memset(&_ih_caps, 0, sizeof _ih_caps);
66 }
67 #endif
68 
69 #ifdef F_SifAllocIopHeap
70 void * SifAllocIopHeap(int size)
71 {
72  union { int size; u32 addr; } arg;
73 
74  if (SifInitIopHeap() < 0)
75  return NULL;
76 
77  arg.size = size;
78 
79  if (SifCallRpc(&_ih_cd, 1, 0, &arg, 4, &arg, 4, NULL, NULL) < 0)
80  return NULL;
81 
82  return (void *)arg.addr;
83 }
84 #endif
85 
86 #ifdef F_SifFreeIopHeap
87 int SifFreeIopHeap(void *addr)
88 {
89  union { void *addr; int result; } arg;
90 
91  if (SifInitIopHeap() < 0)
92  return -E_LIB_API_INIT;
93 
94  arg.addr = addr;
95 
96  if (SifCallRpc(&_ih_cd, 2, 0, &arg, 4, &arg, 4, NULL, NULL) < 0)
97  return -E_SIF_RPC_CALL;
98 
99  return arg.result;
100 }
101 #endif
102 
103 #ifdef F_SifLoadIopHeap
104 
105 #define LIH_PATH_MAX 252
106 
107 struct _iop_load_heap_arg {
108  union {
109  void *addr;
110  int result;
111  } p;
112  char path[LIH_PATH_MAX];
113 };
114 
115 int SifLoadIopHeap(const char *path, void *addr)
116 {
117  struct _iop_load_heap_arg arg;
118 
119  if (SifInitIopHeap() < 0)
120  return -E_LIB_API_INIT;
121 
122  arg.p.addr = addr;
123  strncpy(arg.path, path, LIH_PATH_MAX - 1);
124  arg.path[LIH_PATH_MAX - 1] = 0;
125 
126  if (SifCallRpc(&_ih_cd, 3, 0, &arg, sizeof arg, &arg, 4, NULL, NULL) < 0)
127  return -E_SIF_RPC_CALL;
128 
129  return arg.p.result;
130 }
131 #endif
SifRpcClientData_t _ih_cd
int _ih_caps
int _iop_reboot_count
#define IH_C_BOUND
Definition: iopheap.c:21
void * SifAllocIopHeap(int size)
int SifFreeIopHeap(void *addr)
int SifInitIopHeap(void)
void SifExitIopHeap(void)
int SifLoadIopHeap(const char *path, void *addr)
static void nopdelay(void)
Definition: kernel.h:141
@ E_LIB_API_INIT
Definition: ps2lib_err.h:68
@ E_SIF_RPC_CALL
Definition: ps2lib_err.h:88
@ E_SIF_RPC_BIND
Definition: ps2lib_err.h:86
s32 result
Definition: rpc_client.c:23
void SifInitRpc(int mode)
int SifBindRpc(SifRpcClientData_t *client, int rpc_number, int mode)
int SifCallRpc(SifRpcClientData_t *client, int rpc_number, int mode, void *send, int ssize, void *receive, int rsize, SifRpcEndFunc_t end_function, void *end_param)
struct t_SifRpcServerData * server
Definition: sifrpc.h:142
#define NULL
Definition: tamtypes.h:91
unsigned int u32
Definition: tamtypes.h:30