PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
iopheap.c
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#include "iopheap-common.h"
19
20#include "iopheap.h"
21
22#define IH_C_BOUND 0x0001
23
24extern int _iop_reboot_count;
25extern SifRpcClientData_t _ih_cd;
26extern int _ih_caps;
27
28#ifdef F_SifInitIopHeap
30int _ih_caps = 0;
31
32int SifInitIopHeap()
33{
34 int res;
35
36 static int _rb_count = 0;
37 if (_rb_count != _iop_reboot_count) {
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
55 _ih_caps |= IH_C_BOUND;
56
57 return 0;
58}
59#endif
60
61#ifdef F_SifExitIopHeap
62void SifExitIopHeap()
63{
64 _ih_caps = 0;
65 memset(&_ih_caps, 0, sizeof _ih_caps);
66}
67#endif
68
69#ifdef F_SifAllocIopHeap
70void *SifAllocIopHeap(int size)
71{
72 union
73 {
74 int size;
75 u32 addr;
76 } arg;
77
78 if (SifInitIopHeap() < 0)
79 return NULL;
80
81 arg.size = size;
82
83 if (SifCallRpc(&_ih_cd, 1, 0, &arg, 4, &arg, 4, NULL, NULL) < 0)
84 return NULL;
85
86 return (void *)arg.addr;
87}
88#endif
89
90#ifdef F_SifFreeIopHeap
91int SifFreeIopHeap(void *addr)
92{
93 union
94 {
95 void *addr;
96 int result;
97 } arg;
98
99 if (SifInitIopHeap() < 0)
100 return -E_LIB_API_INIT;
101
102 arg.addr = addr;
103
104 if (SifCallRpc(&_ih_cd, 2, 0, &arg, 4, &arg, 4, NULL, NULL) < 0)
105 return -E_SIF_RPC_CALL;
106
107 return arg.result;
108}
109#endif
110
111#ifdef F_SifLoadIopHeap
112int SifLoadIopHeap(const char *path, void *addr)
113{
114 struct _iop_load_heap_arg arg;
115
116 if (SifInitIopHeap() < 0)
117 return -E_LIB_API_INIT;
118
119 arg.p.addr = addr;
120 strncpy(arg.path, path, LIH_PATH_MAX - 1);
121 arg.path[LIH_PATH_MAX - 1] = 0;
122
123 if (SifCallRpc(&_ih_cd, 3, 0, &arg, sizeof arg, &arg, 4, NULL, NULL) < 0)
124 return -E_SIF_RPC_CALL;
125
126 return arg.p.result;
127}
128#endif
@ 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