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}
66#endif
67
68#ifdef F_SifAllocIopHeap
69void *SifAllocIopHeap(int size)
70{
71 union
72 {
73 int size;
74 u32 addr;
75 } arg;
76
77 if (SifInitIopHeap() < 0)
78 return NULL;
79
80 arg.size = size;
81
82 if (SifCallRpc(&_ih_cd, 1, 0, &arg, 4, &arg, 4, NULL, NULL) < 0)
83 return NULL;
84
85 return (void *)arg.addr;
86}
87#endif
88
89#ifdef F_SifFreeIopHeap
90int SifFreeIopHeap(void *addr)
91{
92 union
93 {
94 void *addr;
95 int result;
96 } arg;
97
98 if (SifInitIopHeap() < 0)
99 return -E_LIB_API_INIT;
100
101 arg.addr = addr;
102
103 if (SifCallRpc(&_ih_cd, 2, 0, &arg, 4, &arg, 4, NULL, NULL) < 0)
104 return -E_SIF_RPC_CALL;
105
106 return arg.result;
107}
108#endif
109
110#ifdef F_SifLoadIopHeap
111int SifLoadIopHeap(const char *path, void *addr)
112{
113 struct _iop_load_heap_arg arg;
114
115 if (SifInitIopHeap() < 0)
116 return -E_LIB_API_INIT;
117
118 arg.p.addr = addr;
119 strncpy(arg.path, path, LIH_PATH_MAX - 1);
120 arg.path[LIH_PATH_MAX - 1] = 0;
121
122 if (SifCallRpc(&_ih_cd, 3, 0, &arg, sizeof arg, &arg, 4, NULL, NULL) < 0)
123 return -E_SIF_RPC_CALL;
124
125 return arg.p.result;
126}
127#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