PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
glue.c
Go to the documentation of this file.
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# (c) 2003 Marcus R. Brown (mrbrown@0xd6.org)
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
16#include "kernel.h"
17
18#ifdef F_DIntr
19int DIntr()
20{
21 int eie, res;
22
23 asm volatile("mfc0\t%0, $12"
24 : "=r"(eie));
25 eie &= 0x10000;
26 res = eie != 0;
27
28 if (!eie)
29 return 0;
30
31 asm(".p2align 3");
32 do {
33 asm volatile("di");
34 asm volatile("sync.p");
35 asm volatile("mfc0\t%0, $12"
36 : "=r"(eie));
37 eie &= 0x10000;
38 } while (eie);
39
40 return res;
41}
42#endif
43
44#ifdef F_EIntr
45int EIntr()
46{
47 int eie;
48
49 asm volatile("mfc0\t%0, $12"
50 : "=r"(eie));
51 eie &= 0x10000;
52 asm volatile("ei");
53
54 return eie != 0;
55}
56#endif
57
58#ifdef F_EnableIntc
59int EnableIntc(int intc)
60{
61 int eie, res;
62
63 asm volatile("mfc0\t%0, $12"
64 : "=r"(eie));
65 eie &= 0x10000;
66
67 if (eie)
68 DI();
69
70 res = _EnableIntc(intc);
71 EE_SYNC();
72
73 if (eie)
74 EI();
75
76 return res;
77}
78#endif
79
80#ifdef F_DisableIntc
81int DisableIntc(int intc)
82{
83 int eie, res;
84
85 asm volatile("mfc0\t%0, $12"
86 : "=r"(eie));
87 eie &= 0x10000;
88
89 if (eie)
90 DI();
91
92 res = _DisableIntc(intc);
93 EE_SYNC();
94
95 if (eie)
96 EI();
97
98 return res;
99}
100#endif
101
102#ifdef F_EnableDmac
103int EnableDmac(int dmac)
104{
105 int eie, res;
106
107 asm volatile("mfc0\t%0, $12"
108 : "=r"(eie));
109 eie &= 0x10000;
110
111 if (eie)
112 DI();
113
114 res = _EnableDmac(dmac);
115 EE_SYNC();
116
117 if (eie)
118 EI();
119
120 return res;
121}
122#endif
123
124#ifdef F_DisableDmac
125int DisableDmac(int dmac)
126{
127 int eie, res;
128
129 asm volatile("mfc0\t%0, $12"
130 : "=r"(eie));
131 eie &= 0x10000;
132
133 if (eie)
134 DI();
135
136 res = _DisableDmac(dmac);
137 EE_SYNC();
138
139 if (eie)
140 EI();
141
142 return res;
143}
144#endif
145
146#ifdef F_SetAlarm
147int SetAlarm(u16 time, void (*callback)(s32 alarm_id, u16 time, void *common), void *common)
148{
149 int eie, res;
150
151 asm volatile("mfc0\t%0, $12"
152 : "=r"(eie));
153 eie &= 0x10000;
154
155 if (eie)
156 DI();
157
158 res = _SetAlarm(time, callback, common);
159 EE_SYNC();
160
161 if (eie)
162 EI();
163
164 return res;
165}
166#endif
167
168#ifdef F_ReleaseAlarm
169int ReleaseAlarm(int alarm_id)
170{
171 int eie, res;
172
173 asm volatile("mfc0\t%0, $12"
174 : "=r"(eie));
175 eie &= 0x10000;
176
177 if (eie)
178 DI();
179
180 res = _ReleaseAlarm(alarm_id);
181 EE_SYNC();
182
183 if (eie)
184 EI();
185
186 return res;
187}
188#endif
189
190#ifdef F_iEnableIntc
191int iEnableIntc(int intc)
192{
193 int res = _iEnableIntc(intc);
194 EE_SYNC();
195
196 return res;
197}
198#endif
199
200#ifdef F_iDisableIntc
201int iDisableIntc(int intc)
202{
203 int res = _iDisableIntc(intc);
204 EE_SYNC();
205
206 return res;
207}
208#endif
209
210#ifdef F_iEnableDmac
211int iEnableDmac(int dmac)
212{
213 int res = _iEnableDmac(dmac);
214 EE_SYNC();
215
216 return res;
217}
218#endif
219
220#ifdef F_iDisableDmac
221int iDisableDmac(int dmac)
222{
223 int res = _iDisableDmac(dmac);
224 EE_SYNC();
225
226 return res;
227}
228#endif
229
230#ifdef F_iSetAlarm
231int iSetAlarm(u16 time, void (*callback)(s32 alarm_id, u16 time, void *common), void *common)
232{
233 int res = _iSetAlarm(time, callback, common);
234 EE_SYNC();
235
236 return res;
237}
238#endif
239
240#ifdef F_iReleaseAlarm
241int iReleaseAlarm(int alarm_id)
242{
243 int res = _iReleaseAlarm(alarm_id);
244 EE_SYNC();
245
246 return res;
247}
248#endif
249
250#ifdef F_SyncDCache
251void SyncDCache(void *start, void *end)
252{
253 int eie;
254
255 asm volatile("mfc0\t%0, $12"
256 : "=r"(eie));
257 eie &= 0x10000;
258
259 if (eie)
260 DI();
261
262 _SyncDCache((void *)((u32)start & 0xffffffc0), (void *)((u32)end & 0xffffffc0));
263
264 if (eie)
265 EI();
266}
267#endif
268
269#ifdef F_iSyncDCache
270void iSyncDCache(void *start, void *end)
271{
272 _SyncDCache((void *)((u32)start & 0xffffffc0), (void *)((u32)end & 0xffffffc0));
273}
274#endif
275
276#ifdef F_InvalidDCache
277void InvalidDCache(void *start, void *end)
278{
279 int eie;
280
281 asm volatile("mfc0\t%0, $12"
282 : "=r"(eie));
283 eie &= 0x10000;
284
285 if (eie)
286 DI();
287
288 _InvalidDCache((void *)((u32)start & 0xffffffc0), (void *)((u32)end & 0xffffffc0));
289
290 if (eie)
291 EI();
292}
293#endif
294
295#ifdef F_iInvalidDCache
296void iInvalidDCache(void *start, void *end)
297{
298 _InvalidDCache((void *)((u32)start & 0xffffffc0), (void *)((u32)end & 0xffffffc0));
299}
300#endif