PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
cdvdstm.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright 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
11#include "irx_imports.h"
12#include "iomanX.h"
13
14#include <cdvd-ioctl.h>
15#include <errno.h>
16#include <kerr.h>
17
18IRX_ID("cdvd_st_driver", 2, 2);
19// Based on the module from SCE SDK 3.1.0.
20
21extern struct irx_export_table _exp_cdvdstm;
22
23extern int cdvdstm_dummyentry(void);
24extern int cdvdstm_termcall(void);
25static unsigned int iop_stream_handler(
26 unsigned int posszarg1, unsigned int posszarg2, void *buffer, int cmdid, const sceCdRMode *rmode, int *error_ptr);
27static unsigned int iop_stream_intr_cb(void *userdata);
28static int cdrom_stm_init(iop_device_t *device);
29static int cdrom_stm_deinit(iop_device_t *device);
30static int cdrom_stm_devctl(
31 iop_file_t *f, const char *name, int cmd, void *inbuf, unsigned int inbuf_len, void *outbuf, unsigned int outbuf_len);
32static void ee_stream_handler_normal(cdrom_stm_devctl_t *instruct, int inbuf_len, int *outres_ptr);
33static unsigned int ee_stream_intr_cb_normal(void *userdata);
34static void ee_stream_handler_cdda(cdrom_stm_devctl_t *instruct, int inbuf_len, int *outres_ptr);
35static unsigned int ee_stream_intr_cb_cdda(void *userdata);
36extern unsigned int optimized_memcpy(char *dst, const char *src, unsigned int n);
37
38static void iop_stream_intr_cb_thunk(int userdata)
39{
40 iop_stream_intr_cb((void *)userdata);
41}
42
43static void ee_stream_intr_cb_normal_thunk(int userdata)
44{
45 ee_stream_intr_cb_normal((void *)userdata);
46}
47
48static void ee_stream_intr_cb_cdda_thunk(int userdata)
49{
50 ee_stream_intr_cb_cdda((void *)userdata);
51}
52
53static int g_verbose_level = 0;
54static int g_cdvdstm_in_deldrv = 0;
55static int g_cdvdstm_bufmax = 0;
56static int g_cdvdstm_numbytes = 0;
57static int g_cdvdstm_bankmax = 0;
58static void *g_cdvdstm_buffer = NULL;
59static unsigned int g_cdvdstm_sectorcount = 0;
60static int g_cdvdstm_last_error_for_iop = 0;
61static int g_cdvdstm_retryerr_iop = 0;
62static int g_cdvdstm_retrycnt_iop = 0;
63
64IOMANX_RETURN_VALUE_IMPL(EIO);
65
66static iop_device_ops_t g_cdrom_stm_dev_ops = {
67 &cdrom_stm_init, // init,
68 &cdrom_stm_deinit, // deinit,
69 IOMANX_RETURN_VALUE(EIO), // format,
70 IOMANX_RETURN_VALUE(EIO), // open,
71 IOMANX_RETURN_VALUE(EIO), // close,
72 IOMANX_RETURN_VALUE(EIO), // read,
73 IOMANX_RETURN_VALUE(EIO), // write,
74 IOMANX_RETURN_VALUE(EIO), // lseek,
75 IOMANX_RETURN_VALUE(EIO), // ioctl,
76 IOMANX_RETURN_VALUE(EIO), // remove,
77 IOMANX_RETURN_VALUE(EIO), // mkdir,
78 IOMANX_RETURN_VALUE(EIO), // rmdir,
79 IOMANX_RETURN_VALUE(EIO), // dopen,
80 IOMANX_RETURN_VALUE(EIO), // dclose,
81 IOMANX_RETURN_VALUE(EIO), // dread,
82 IOMANX_RETURN_VALUE(EIO), // getstat,
83 IOMANX_RETURN_VALUE(EIO), // chstat,
84 IOMANX_RETURN_VALUE(EIO), // rename,
85 IOMANX_RETURN_VALUE(EIO), // chdir,
86 IOMANX_RETURN_VALUE(EIO), // sync,
87 IOMANX_RETURN_VALUE(EIO), // mount,
88 IOMANX_RETURN_VALUE(EIO), // umount,
89 IOMANX_RETURN_VALUE_S64(EIO), // lseek64,
90 &cdrom_stm_devctl,
91 IOMANX_RETURN_VALUE(EIO), // symlink
92 IOMANX_RETURN_VALUE(EIO), // readlink
93 IOMANX_RETURN_VALUE(EIO), // ioctl2
94};
95static iop_device_t g_cdrom_stm_dev = {"cdrom_stm", IOP_DT_FSEXT | IOP_DT_FS, 1, "CD-ROM_STM ", &g_cdrom_stm_dev_ops};
96static int g_cdvdstm_last_error_for_ee = 0;
97static int g_cdvdstm_bufsz2 = 0;
98static int g_cdvdstm_chunksz2 = 0;
99static int g_cdvdstm_bankcnt2 = 0;
100static void *g_cdvdstm_buffer2 = NULL;
101static u32 g_cdvdstm_sectorcount2 = 0;
102static int g_cdvdstm_retryerr_ee = 0;
103static int g_cdvdstm_retrycnt_ee_normal = 0;
104static int g_cdvdstm_usedchunksize2 = 0x930;
105static u32 g_cdvdstm_retrycnt_ee_cdda = 0;
106static sceCdRMode g_rmode_for_stream0;
107static int g_cdvdstm_tgt;
108static int g_cdvdstm_semid;
109static int g_cdvdman_intr_efid;
110static char g_cdvdstm_usedmap_iop[512];
111static unsigned int g_cdvdstm_lsn_iop;
112static int g_cdvdstm_bankgp_iop;
113static int g_cdvdstm_bankcur_iop;
114static int g_cdvdstm_bankoffs_iop;
115static sceCdRMode g_cdvdstm_mode_iop;
116static int g_cdvdstm_stmstart_iop;
117static iop_sys_clock_t g_cdvdstm_curclk_iop;
118static SifDmaTransfer_t g_cdvdstm_dmat;
119static int g_cdvdstm_readlbn_ee_normal;
120static SifDmaTransfer_t g_cdvdstm_dmat2;
121static u32 g_cdvdstm_readlbn_ee_cdda;
122static char g_cdvdstm_usedmap_ee[512];
123static u32 g_cdvdstm_lsn_ee;
124static int g_cdvdstm_bankgp_ee;
125static int g_cdvdstm_bankcur_ee;
126static int g_cdvdstm_bankoffs_ee;
127static sceCdRMode g_cdvdstm_mode_ee;
128static int g_cdvdstm_stmstart_ee;
129static iop_sys_clock_t g_cdvdstm_curclk_ee;
130
131static int vCancelAlarm(unsigned int (*alarm_cb)(void *), void *arg)
132{
133 return (QueryIntrContext() ? iCancelAlarm : CancelAlarm)(alarm_cb, arg);
134}
135
136static int vSetEventFlag(void)
137{
138 return (QueryIntrContext() ? iSetEventFlag : SetEventFlag)(g_cdvdman_intr_efid, 8);
139}
140
141static int vClearEventFlag(void)
142{
143 return (QueryIntrContext() ? iClearEventFlag : ClearEventFlag)(g_cdvdman_intr_efid, ~8);
144}
145
146int cdvdstm_dummyentry(void)
147{
148 VERBOSE_PRINTF(1, "Dummy Entry Called\n");
149 return 0;
150}
151
152int cdvdstm_termcall(void)
153{
154 cdrom_stm_devctl_t instruct;
155 int outres;
156
157 memset(&instruct, 0, sizeof(instruct));
158 instruct.m_cmdid = 3;
159 instruct.m_rmode.datapattern = SCECdSecS2048;
160 instruct.m_rmode.spindlctrl = SCECdSpinMax;
161 instruct.m_rmode.trycount = 0;
162 ee_stream_handler_normal(&instruct, 0x14, &outres);
163 sceCdStStop();
164 return 0;
165}
166
167static int stm_iop_read_timeout_alarm_cb(const iop_sys_clock_t *sys_clock)
168{
169 KPRINTF("Stm Iop Read Time Out %d(msec)\n", sys_clock->lo / 0x9000);
170 return !sceCdBreak();
171}
172
173static int sceCdStream0_inner(unsigned int rdsize, char *addrarg, int modearg, int *error_ptr)
174{
175 int cur_size;
176 unsigned int streamres;
177 int last_error;
178 u32 efbits;
179 int err;
180
181 VERBOSE_KPRINTF(1, "sceCdStream0 call read size= %d mode= %d addr= %08x\n", rdsize, modearg, addrarg);
182 cur_size = 0;
183 if ( !sceCdSC(0xFFFFFFFF, &last_error) )
184 return 0;
185 *error_ptr = 0;
186 if ( !modearg )
187 return iop_stream_handler(0, rdsize, addrarg, 2, &g_rmode_for_stream0, error_ptr);
188 vSetEventFlag();
189 err = 0;
190 streamres = 0;
191 while ( (!err || streamres) )
192 {
193 WaitEventFlag(g_cdvdman_intr_efid, 8, WEF_AND, &efbits);
194 streamres = iop_stream_handler(0, rdsize - cur_size, &addrarg[cur_size], 2, &g_rmode_for_stream0, &err);
195 if ( rdsize - cur_size != streamres )
196 vClearEventFlag();
197 cur_size += streamres;
198 if ( err )
199 *error_ptr = err;
200 VERBOSE_KPRINTF(1, "sceCdStream0 BLK cur_size= %d req_size= %d err 0x%x\n", cur_size, rdsize, err);
201 if ( (unsigned int)cur_size == rdsize )
202 break;
203 }
204 return cur_size;
205}
206
207static int sceCdStream0(int rdsize_sectors, char *addrarg, int modearg, int *error_ptr)
208{
209 return sceCdStream0_inner(rdsize_sectors << 11, addrarg, modearg, error_ptr) / 0x800;
210}
211
212static unsigned int iop_stream_handler(
213 unsigned int posszarg1, unsigned int posszarg2, void *buffer, int cmdid, const sceCdRMode *rmode, int *error_ptr)
214{
215 int retryflag;
216 int bankcur_tmp;
217 unsigned int i;
218 unsigned int written_chunk_size_tmp;
219 int bankcur_next_tmp1;
220 int chunk_size;
221 int bankcur_next_tmp2;
222 int state;
223
224 retryflag = 0;
225 VERBOSE_KPRINTF(1, "CD Stream Call mode= %d\n", cmdid);
226 *error_ptr = 0;
227 if ( g_cdvdstm_stmstart_iop == 2 && cmdid != 9 && cmdid != 3 )
228 {
229 return 0;
230 }
231 switch ( cmdid )
232 {
233 case 8:
234 sceCdSC(1, &g_cdvdstm_last_error_for_iop);
235 if ( sceCdNop() )
236 return 1;
237 sceCdSC(0, &g_cdvdstm_last_error_for_iop);
238 return 0;
239 case 7:
240 CpuSuspendIntr(&state);
241 vCancelAlarm((unsigned int (*)(void *))iop_stream_intr_cb, &g_cdvdstm_curclk_iop);
242 sceCdSC(0, &g_cdvdstm_last_error_for_iop);
243 CpuResumeIntr(state);
244 sceCdSync(0);
245 vCancelAlarm((unsigned int (*)(void *))stm_iop_read_timeout_alarm_cb, &g_cdvdstm_curclk_iop);
246 return 1;
247 case 6:
248 bankcur_tmp = g_cdvdstm_bankcur_iop;
249 if ( !g_cdvdstm_usedmap_iop[bankcur_tmp] )
250 {
251 bankcur_tmp += 1;
252 if ( (unsigned int)bankcur_tmp >= (unsigned int)g_cdvdstm_bankmax )
253 bankcur_tmp = 0;
254 if ( !g_cdvdstm_usedmap_iop[bankcur_tmp] )
255 bankcur_tmp = g_cdvdstm_bankcur_iop;
256 }
257 for ( i = 0; (i < (unsigned int)g_cdvdstm_bankmax) && g_cdvdstm_usedmap_iop[bankcur_tmp]
258 && (g_cdvdstm_bankgp_iop != bankcur_tmp);
259 i += 1 )
260 {
261 bankcur_tmp += 1;
262 if ( (unsigned int)bankcur_tmp >= (unsigned int)g_cdvdstm_bankmax )
263 bankcur_tmp = 0;
264 }
265 return i * ((unsigned int)g_cdvdstm_numbytes >> 11);
266 case 5:
267 sceCdstm0Cb((void (*)(int))iop_stream_intr_cb_thunk);
268 g_cdvdstm_bufmax = posszarg1;
269 g_cdvdstm_sectorcount = posszarg1 / posszarg2;
270 g_cdvdstm_numbytes = g_cdvdstm_sectorcount << 11;
271 g_cdvdstm_buffer = buffer;
272 g_cdvdstm_bankmax = posszarg2;
273 KPRINTF(
274 "Stream Buffer 1Bank %dbyte %dbanks addr:%08x %dbyte used.\n",
275 g_cdvdstm_numbytes,
276 posszarg2,
277 buffer,
278 g_cdvdstm_numbytes * posszarg2);
279 return 1;
280 case 3:
281 CpuSuspendIntr(&state);
282 g_cdvdstm_stmstart_iop = 0;
283 vCancelAlarm((unsigned int (*)(void *))iop_stream_intr_cb, &g_cdvdstm_curclk_iop);
284 sceCdSC(0, &g_cdvdstm_last_error_for_iop);
285 CpuResumeIntr(state);
286 sceCdBreak();
287 for ( i = 0; i < (unsigned int)g_cdvdstm_bankmax; i += 1 )
288 g_cdvdstm_usedmap_iop[i] = 0;
289 g_cdvdstm_bankoffs_iop = 0;
290 g_cdvdstm_bankcur_iop = 0;
291 g_cdvdstm_bankgp_iop = 0;
292 sceCdSync(0);
293 g_cdvdstm_last_error_for_iop = 0;
294 sceCdSC(0xFFFFFFFE, &g_cdvdstm_last_error_for_iop);
295 vCancelAlarm((unsigned int (*)(void *))stm_iop_read_timeout_alarm_cb, &g_cdvdstm_curclk_iop);
296 return 1;
297 case 9:
298 if ( sceCdSC(0xFFFFFFFF, &g_cdvdstm_last_error_for_iop) )
299 {
300 CpuSuspendIntr(&state);
301 g_cdvdstm_lsn_iop = posszarg1;
302 for ( i = 0; i < (unsigned int)g_cdvdstm_bankmax; i += 1 )
303 g_cdvdstm_usedmap_iop[i] = 0;
304 g_cdvdstm_stmstart_iop = 2;
305 CpuResumeIntr(state);
306 return 1;
307 }
308 return 0;
309 case 1:
310 g_cdvdstm_mode_iop.datapattern = rmode->datapattern;
311 g_cdvdstm_mode_iop.trycount = rmode->trycount;
312 g_cdvdstm_mode_iop.spindlctrl = rmode->spindlctrl;
313 g_cdvdstm_retryerr_iop = 0;
314 break;
315 case 4:
316 CpuSuspendIntr(&state);
317 vCancelAlarm((unsigned int (*)(void *))iop_stream_intr_cb, &g_cdvdstm_curclk_iop);
318 sceCdSC(0, &g_cdvdstm_last_error_for_iop);
319 retryflag = 1;
320 CpuResumeIntr(state);
321 posszarg2 = 0;
322 cmdid = 1;
323 g_cdvdstm_lsn_iop = posszarg1;
324 g_cdvdstm_bankoffs_iop = 0;
325 g_cdvdstm_bankcur_iop = 0;
326 g_cdvdstm_bankgp_iop = 0;
327 sceCdSync(0);
328 vCancelAlarm((unsigned int (*)(void *))stm_iop_read_timeout_alarm_cb, &g_cdvdstm_curclk_iop);
329 break;
330 }
331 if ( cmdid == 1 )
332 {
333 CpuSuspendIntr(&state);
334 retryflag = 1;
335 vCancelAlarm((unsigned int (*)(void *))iop_stream_intr_cb, &g_cdvdstm_curclk_iop);
336 sceCdSC(0, &g_cdvdstm_last_error_for_iop);
337 CpuResumeIntr(state);
338 for ( i = 0; i < (unsigned int)g_cdvdstm_bankmax; i += 1 )
339 g_cdvdstm_usedmap_iop[i] = 0;
340 g_cdvdstm_lsn_iop = posszarg1;
341 sceCdSC(0xFFFFFFE9, (int *)&g_cdvdstm_lsn_iop);
342 g_cdvdstm_bankoffs_iop = 0;
343 g_cdvdstm_bankcur_iop = 0;
344 g_cdvdstm_bankgp_iop = 0;
345 sceCdSync(0);
346 vCancelAlarm((unsigned int (*)(void *))stm_iop_read_timeout_alarm_cb, &g_cdvdstm_curclk_iop);
347 g_cdvdstm_stmstart_iop = 1;
348 sceCdSC(1, &g_cdvdstm_last_error_for_iop);
349 if ( !sceCdNop() )
350 {
351 sceCdSC(0, &g_cdvdstm_last_error_for_iop);
352 return 0;
353 }
354 }
355 CpuSuspendIntr(&state);
356 written_chunk_size_tmp = -1;
357 for ( i = 0; i < posszarg2; i += chunk_size )
358 {
359 if ( !g_cdvdstm_usedmap_iop[g_cdvdstm_bankcur_iop] )
360 {
361 VERBOSE_KPRINTF(
362 1,
363 "CD read buffer over run %d %d %d %d %d gp %d pp %d\n",
364 (u8)g_cdvdstm_usedmap_iop[0],
365 (u8)g_cdvdstm_usedmap_iop[1],
366 (u8)g_cdvdstm_usedmap_iop[2],
367 (u8)g_cdvdstm_usedmap_iop[3],
368 (u8)g_cdvdstm_usedmap_iop[4],
369 g_cdvdstm_bankgp_iop,
370 g_cdvdstm_bankcur_iop);
371 bankcur_next_tmp1 = g_cdvdstm_bankcur_iop;
372 g_cdvdstm_bankcur_iop += 1;
373 if ( (unsigned int)g_cdvdstm_bankcur_iop >= (unsigned int)g_cdvdstm_bankmax )
374 g_cdvdstm_bankcur_iop = 0;
375 written_chunk_size_tmp = i;
376 if ( !g_cdvdstm_usedmap_iop[g_cdvdstm_bankcur_iop] )
377 {
378 g_cdvdstm_bankcur_iop = bankcur_next_tmp1;
379 }
380 break;
381 }
382 if ( (unsigned int)g_cdvdstm_bankoffs_iop >= (unsigned int)g_cdvdstm_numbytes )
383 {
384 g_cdvdstm_bankoffs_iop = 0;
385 g_cdvdstm_usedmap_iop[g_cdvdstm_bankcur_iop] = 0;
386 bankcur_next_tmp2 = g_cdvdstm_bankcur_iop;
387 g_cdvdstm_bankcur_iop += 1;
388 if ( (unsigned int)g_cdvdstm_bankcur_iop >= (unsigned int)g_cdvdstm_bankmax )
389 g_cdvdstm_bankcur_iop = 0;
390 if ( !g_cdvdstm_usedmap_iop[g_cdvdstm_bankcur_iop] || g_cdvdstm_bankgp_iop == g_cdvdstm_bankcur_iop )
391 {
392 g_cdvdstm_bankcur_iop = bankcur_next_tmp2;
393 written_chunk_size_tmp = i;
394 VERBOSE_KPRINTF(
395 1,
396 "CD read buffer over run %d %d %d %d %d gp %d pp %d\n",
397 (u8)g_cdvdstm_usedmap_iop[0],
398 (u8)g_cdvdstm_usedmap_iop[1],
399 (u8)g_cdvdstm_usedmap_iop[2],
400 (u8)g_cdvdstm_usedmap_iop[3],
401 (u8)g_cdvdstm_usedmap_iop[4],
402 g_cdvdstm_bankgp_iop,
403 g_cdvdstm_bankcur_iop);
404 break;
405 }
406 }
407 optimized_memcpy(
408 &((char *)buffer)[i],
409 &((char *)g_cdvdstm_buffer)[g_cdvdstm_bankcur_iop * g_cdvdstm_numbytes + g_cdvdstm_bankoffs_iop],
410 0x800);
411 chunk_size = ((unsigned int)0x800 > posszarg2 - i) ? (posszarg2 - i) : 0x800;
412 g_cdvdstm_bankoffs_iop += chunk_size;
413 }
414 if ( written_chunk_size_tmp == 0xFFFFFFFF )
415 written_chunk_size_tmp = posszarg2;
416 CpuResumeIntr(state);
417 if ( !retryflag )
418 {
419 if ( sceCdSC(0xFFFFFFFF, &g_cdvdstm_last_error_for_iop) != 1 && !written_chunk_size_tmp && !g_cdvdstm_retryerr_iop )
420 {
421 g_cdvdstm_retryerr_iop = 273;
422 }
423 *error_ptr = g_cdvdstm_retryerr_iop;
424 g_cdvdstm_retryerr_iop = 0;
425 return written_chunk_size_tmp;
426 }
427 return 1;
428}
429
430static unsigned int iop_stream_intr_cb(void *userdata)
431{
432 int last_error;
433 int scres_unused;
434
435 (void)userdata;
436
437 VERBOSE_KPRINTF(1, "Intr Read call\n");
438 iCancelAlarm((unsigned int (*)(void *))stm_iop_read_timeout_alarm_cb, &g_cdvdstm_curclk_iop);
439 iCancelAlarm((unsigned int (*)(void *))iop_stream_intr_cb, &g_cdvdstm_curclk_iop);
440 sceCdSC(0xFFFFFFFF, &last_error);
441 if ( !last_error )
442 {
443#ifdef CDVD_VARIANT_XOSD
444 switch ( sceCdSC(0xFFFFFFDA, &scres_unused) )
445#else
446 switch ( sceCdGetDiskType() )
447#endif
448 {
449 case SCECdPSCD:
450 case SCECdPSCDDA:
451 case SCECdPS2CD:
452 case SCECdPS2CDDA:
453 case SCECdPS2DVD:
454 break;
455 default:
456 last_error = SCECdErREADCF;
457 break;
458 }
459 }
460 g_cdvdstm_curclk_iop.hi = 0;
461 if ( g_cdvdstm_stmstart_iop )
462 g_cdvdstm_retrycnt_iop = 0;
463 if ( g_cdvdstm_stmstart_iop || last_error || g_cdvdstm_retrycnt_iop )
464 {
465 VERBOSE_KPRINTF(
466 1, "Stm Rtry stmstart:%d err:%02x retry:%d\n", g_cdvdstm_stmstart_iop, last_error, g_cdvdstm_retrycnt_iop);
467 }
468 g_cdvdstm_curclk_iop.lo = (g_cdvdstm_stmstart_iop || last_error || g_cdvdstm_retrycnt_iop) ?
469 0x20f58000 :
470 (0x9000 * sceCdSC(0xFFFFFFEF, &scres_unused));
471 if ( last_error )
472 {
473 VERBOSE_KPRINTF(1, "IOP Stream read Error code= 0x%02x retry= %d\n", last_error, g_cdvdstm_retrycnt_iop);
474 if ( last_error == SCECdErREAD || last_error == SCECdErABRT )
475 {
476 VERBOSE_KPRINTF(1, "On err %08x\n", last_error);
477 if ( g_cdvdstm_retrycnt_iop )
478 g_cdvdstm_retryerr_iop = last_error;
479 g_cdvdstm_retrycnt_iop = 3;
480 }
481 else
482 {
483 g_cdvdstm_retryerr_iop = last_error;
484 g_cdvdstm_retrycnt_iop = 1;
485 }
486 }
487 if ( g_cdvdstm_retrycnt_iop )
488 {
489 unsigned int tgttmp;
490
491 g_cdvdstm_retrycnt_iop -= 1;
492 tgttmp = ((unsigned int)g_cdvdstm_tgt >= (unsigned int)(0x10 * g_cdvdstm_retrycnt_iop)) ?
493 (g_cdvdstm_tgt - 0x10 * g_cdvdstm_retrycnt_iop) :
494 (g_cdvdstm_tgt + 0x10 * g_cdvdstm_retrycnt_iop);
495 VERBOSE_KPRINTF(1, "Stm Rtry Start Tgt=%d Cur= %d\n", g_cdvdstm_tgt, tgttmp);
496 if ( sceCdRE(
497 tgttmp,
498 g_cdvdstm_sectorcount,
499 (char *)g_cdvdstm_buffer + g_cdvdstm_bankgp_iop * g_cdvdstm_numbytes,
500 &g_cdvdstm_mode_iop) )
501 {
502 iSetAlarm(&g_cdvdstm_curclk_iop, (unsigned int (*)(void *))stm_iop_read_timeout_alarm_cb, &g_cdvdstm_curclk_iop);
503 }
504 else
505 {
506 g_cdvdstm_curclk_iop.lo = 0x708000;
507 if (
508 iSetAlarm(&g_cdvdstm_curclk_iop, (unsigned int (*)(void *))iop_stream_intr_cb, &g_cdvdstm_curclk_iop)
509 && !sceCdNop() )
510 {
511 sceCdSC(0, &last_error);
512 }
513 g_cdvdstm_retrycnt_iop += 1;
514 }
515 return 0;
516 }
517 else
518 {
519 int gptmp;
520
521 if ( !g_cdvdstm_stmstart_iop )
522 {
523 g_cdvdstm_usedmap_iop[g_cdvdstm_bankgp_iop] = 1;
524 gptmp = g_cdvdstm_bankgp_iop;
525 g_cdvdstm_bankgp_iop += 1;
526 if ( (unsigned int)g_cdvdstm_bankgp_iop >= (unsigned int)g_cdvdstm_bankmax )
527 g_cdvdstm_bankgp_iop = 0;
528 }
529 if (
530 !g_cdvdstm_stmstart_iop
531 && (g_cdvdstm_usedmap_iop[g_cdvdstm_bankgp_iop] || g_cdvdstm_bankcur_iop == g_cdvdstm_bankgp_iop) )
532 {
533 g_cdvdstm_bankgp_iop = gptmp;
534 g_cdvdstm_usedmap_iop[gptmp] = 0;
535 VERBOSE_KPRINTF(
536 1,
537 "read Full %d %d %d %d %d gp %d pp %d spn %d\n",
538 (u8)g_cdvdstm_usedmap_iop[0],
539 (u8)g_cdvdstm_usedmap_iop[1],
540 (u8)g_cdvdstm_usedmap_iop[2],
541 (u8)g_cdvdstm_usedmap_iop[3],
542 (u8)g_cdvdstm_usedmap_iop[4],
543 g_cdvdstm_bankgp_iop,
544 g_cdvdstm_bankcur_iop,
545 g_cdvdstm_mode_iop.spindlctrl);
546 g_cdvdstm_curclk_iop.lo = 0x48000;
547 if (
548 iSetAlarm(&g_cdvdstm_curclk_iop, (unsigned int (*)(void *))iop_stream_intr_cb, &g_cdvdstm_curclk_iop)
549 && !sceCdNop() )
550 {
551 sceCdSC(0, &last_error);
552 }
553 }
554 else
555 {
556 if ( g_cdvdstm_stmstart_iop == 2 )
557 {
558 unsigned int i;
559
560 g_cdvdstm_bankoffs_iop = 0;
561 g_cdvdstm_bankcur_iop = 0;
562 g_cdvdstm_bankgp_iop = 0;
563 for ( i = 0; i < (unsigned int)g_cdvdstm_bankmax; i += 1 )
564 g_cdvdstm_usedmap_iop[i] = 0;
565 }
566 g_cdvdstm_stmstart_iop = 0;
567 g_cdvdstm_tgt = g_cdvdstm_lsn_iop;
568 if ( sceCdRE(
569 g_cdvdstm_lsn_iop,
570 g_cdvdstm_sectorcount,
571 (char *)g_cdvdstm_buffer + g_cdvdstm_bankgp_iop * g_cdvdstm_numbytes,
572 &g_cdvdstm_mode_iop) )
573 {
574 iSetAlarm(
575 &g_cdvdstm_curclk_iop, (unsigned int (*)(void *))stm_iop_read_timeout_alarm_cb, &g_cdvdstm_curclk_iop);
576 }
577 else
578 {
579 g_cdvdstm_curclk_iop.lo = 0x708000;
580 if (
581 iSetAlarm(&g_cdvdstm_curclk_iop, (unsigned int (*)(void *))iop_stream_intr_cb, &g_cdvdstm_curclk_iop)
582 && !sceCdNop() )
583 {
584 sceCdSC(0, &last_error);
585 }
586 g_cdvdstm_retrycnt_iop = 1;
587 }
588 g_cdvdstm_lsn_iop += g_cdvdstm_sectorcount;
589 }
590 }
591 return 0;
592}
593
594static int cdrom_stm_init(iop_device_t *device)
595{
596 (void)device;
597 iop_sema_t semaparam;
598
599 semaparam.attr = SA_THPRI;
600 semaparam.initial = 1;
601 semaparam.max = 1;
602 semaparam.option = 0;
603 g_cdvdstm_semid = CreateSema(&semaparam);
604 return 0;
605}
606
607static int cdrom_stm_deinit(iop_device_t *device)
608{
609 (void)device;
610 SignalSema(g_cdvdstm_semid);
611 DeleteSema(g_cdvdstm_semid);
612 return 0;
613}
614
615static int cdrom_stm_devctl(
616 iop_file_t *f, const char *name, int cmd, void *inbuf, unsigned int inbuf_len, void *outbuf, unsigned int outbuf_len)
617{
618 int retres;
619 cdrom_stm_devctl_t *instruct;
620 int *outres_ptr;
621
622 (void)f;
623 (void)name;
624 (void)outbuf_len;
625
626 instruct = inbuf;
627 outres_ptr = outbuf;
628 WaitSema(g_cdvdstm_semid);
629 retres = 0;
630 if ( g_cdvdstm_in_deldrv )
631 {
632 SignalSema(g_cdvdstm_semid);
633 return -EIO;
634 }
635 switch ( cmd )
636 {
637 case 0x4393:
638 if ( instruct->m_cmdid == 5 || instruct->m_cmdid == 3 || instruct->m_cmdid - 7 < 2 )
639 {
640 vSetEventFlag();
641 }
642 *outres_ptr = iop_stream_handler(
643 instruct->m_posszarg1,
644 instruct->m_posszarg2,
645 instruct->m_buffer,
646 instruct->m_cmdid,
647 &instruct->m_rmode,
648 (int *)&instruct->m_error);
649 break;
650 case 0x4394:
651 *outres_ptr =
652 sceCdStream0(instruct->m_posszarg2, (char *)instruct->m_buffer, instruct->m_cmdid, (int *)&instruct->m_error);
653 break;
654 case 0x4396:
655 ee_stream_handler_normal(instruct, inbuf_len, outres_ptr);
656 break;
657 case 0x4398:
658 ee_stream_handler_cdda(instruct, inbuf_len, outres_ptr);
659 break;
660 default:
661 // The following printf was removed for ioprp300x
662 PRINTF("Un-support devctl %08x\n", cmd);
663 retres = -EIO;
664 break;
665 }
666 SignalSema(g_cdvdstm_semid);
667 return retres;
668}
669
670int _start(int ac, char *av[], void *startaddr, ModuleInfo_t *mi)
671{
672 int last_error;
673 int scres_unused;
674 int state;
675
676 (void)av;
677 (void)startaddr;
678
679 if ( ac < 0 )
680 {
681 int relres;
682
683 if ( !sceCdSC(0xFFFFFFFF, &last_error) )
684 {
685 return MODULE_REMOVABLE_END;
686 }
687 g_cdvdstm_in_deldrv = 1;
688 DelDrv(g_cdrom_stm_dev.name);
689 CpuSuspendIntr(&state);
690 relres = ReleaseLibraryEntries(&_exp_cdvdstm);
691 CpuResumeIntr(state);
692 g_cdvdstm_in_deldrv = 0;
693 if ( relres && relres != KE_LIBRARY_NOTFOUND )
694 {
695 g_cdvdstm_in_deldrv = 0;
696 return MODULE_REMOVABLE_END;
697 }
698 return MODULE_NO_RESIDENT_END;
699 }
700 if ( RegisterLibraryEntries(&_exp_cdvdstm) )
701 return MODULE_NO_RESIDENT_END;
702 DelDrv(g_cdrom_stm_dev.name);
703 if ( AddDrv(&g_cdrom_stm_dev) )
704 {
705 cdrom_stm_deinit(&g_cdrom_stm_dev);
706 return MODULE_NO_RESIDENT_END;
707 }
708 g_cdvdman_intr_efid = sceCdSC(0xFFFFFFF5, &scres_unused);
709#if 0
710 return MODULE_REMOVABLE_END;
711#else
712 if ( mi && ((mi->newflags & 2) != 0) )
713 mi->newflags |= 0x10;
714 return MODULE_RESIDENT_END;
715#endif
716}
717
718static int vsceSifDmaStat(int dmat)
719{
720#ifdef CDVD_VARIANT_XOSD
721 int st;
722 int state;
723
724 if ( QueryIntrContext() )
725 return sceSifDmaStat(dmat);
726 CpuSuspendIntr(&state);
727 st = sceSifDmaStat(dmat);
728 CpuResumeIntr(state);
729 return st;
730#else
731 return sceSifDmaStat(dmat);
732#endif
733}
734
735static int stm_ee_read_timeout_alarm_cb(const iop_sys_clock_t *sys_clock)
736{
737 int read_timeout;
738
739 read_timeout = sys_clock->lo / 0x9000;
740 KPRINTF("Stm EE Read Time Out %d(msec)\n", read_timeout);
741 sceCdSC(0xFFFFFFEE, &read_timeout);
742 return !sceCdBreak();
743}
744
745static void ee_stream_handler_normal(cdrom_stm_devctl_t *instruct, int inbuf_len, int *outres_ptr)
746{
747 int retryflag;
748 u32 cmdid;
749 u32 posszarg2_bytes;
750 int bankcur_tmp;
751 unsigned int chunks_sectors;
752 int bankcur_next_tmp1;
753 int posszarg2_bytes_clamped;
754 int dmat1;
755 int bankcur_next_tmp2;
756 int posszarg2_bytes_overrun;
757 int outres_tmp2;
758 int state;
759 unsigned int i;
760
761 (void)inbuf_len;
762
763 retryflag = 0;
764 cmdid = instruct->m_cmdid;
765 if ( g_cdvdstm_stmstart_ee == 2 && (cmdid != 9 && cmdid != 3) )
766 {
767 *outres_ptr = 0;
768 return;
769 }
770 switch ( cmdid )
771 {
772 case 8:
773 sceCdSC(2, &g_cdvdstm_last_error_for_ee);
774 if ( !sceCdNop() )
775 {
776 sceCdSC(0, &g_cdvdstm_last_error_for_ee);
777 *outres_ptr = 0;
778 return;
779 }
780 *outres_ptr = 1;
781 return;
782 case 7:
783 CpuSuspendIntr(&state);
784 CancelAlarm((unsigned int (*)(void *))ee_stream_intr_cb_normal, &g_cdvdstm_curclk_ee);
785 sceCdSC(0, &g_cdvdstm_last_error_for_ee);
786 CpuResumeIntr(state);
787 sceCdSync(0);
788 *outres_ptr = 1;
789 CancelAlarm((unsigned int (*)(void *))stm_ee_read_timeout_alarm_cb, &g_cdvdstm_curclk_ee);
790 return;
791 case 6:
792 bankcur_tmp = g_cdvdstm_bankcur_ee;
793 if ( !g_cdvdstm_usedmap_ee[bankcur_tmp] )
794 {
795 bankcur_tmp += 1;
796 if ( (unsigned int)bankcur_tmp >= (unsigned int)g_cdvdstm_bankcnt2 )
797 bankcur_tmp = 0;
798 if ( !g_cdvdstm_usedmap_ee[bankcur_tmp] )
799 bankcur_tmp = g_cdvdstm_bankcur_ee;
800 }
801 for ( i = 0; (i < (unsigned int)g_cdvdstm_bankcnt2) && g_cdvdstm_usedmap_ee[bankcur_tmp]
802 && (g_cdvdstm_bankgp_ee != bankcur_tmp);
803 i += 1 )
804 {
805 bankcur_tmp += 1;
806 if ( (unsigned int)bankcur_tmp >= (unsigned int)g_cdvdstm_bankcnt2 )
807 bankcur_tmp = 0;
808 }
809 *outres_ptr = i * ((unsigned int)g_cdvdstm_chunksz2 >> 11);
810 return;
811 case 5:
812 sceCdstm1Cb((void (*)(int))ee_stream_intr_cb_normal_thunk);
813 if ( !instruct->m_posszarg2 )
814 __builtin_trap();
815 chunks_sectors = instruct->m_posszarg1 / instruct->m_posszarg2;
816 g_cdvdstm_bufsz2 = instruct->m_posszarg1;
817 g_cdvdstm_sectorcount2 = chunks_sectors;
818 g_cdvdstm_chunksz2 = chunks_sectors << 11;
819 g_cdvdstm_buffer2 = (char *)instruct->m_buffer;
820 g_cdvdstm_bankcnt2 = instruct->m_posszarg2;
821 PRINTF(
822 "Stream Buffer 1Bank %dbyte %dbanks %dbyte used\n",
823 (int)(chunks_sectors << 11),
824 (int)(instruct->m_posszarg2),
825 (int)((chunks_sectors << 11) * (instruct->m_posszarg2)));
826 *outres_ptr = 1;
827 return;
828 case 3:
829 CpuSuspendIntr(&state);
830 g_cdvdstm_stmstart_ee = 0;
831 CancelAlarm((unsigned int (*)(void *))ee_stream_intr_cb_normal, &g_cdvdstm_curclk_ee);
832 sceCdSC(0, &g_cdvdstm_last_error_for_ee);
833 CpuResumeIntr(state);
834 sceCdBreak();
835 for ( i = 0; i < (unsigned int)g_cdvdstm_bankcnt2; i += 1 )
836 {
837 g_cdvdstm_usedmap_ee[i] = 0;
838 }
839 g_cdvdstm_bankoffs_ee = 0;
840 g_cdvdstm_bankcur_ee = 0;
841 g_cdvdstm_bankgp_ee = 0;
842 *outres_ptr = 1;
843 sceCdSync(0);
844 g_cdvdstm_last_error_for_ee = 0;
845 sceCdSC(0xFFFFFFFE, &g_cdvdstm_last_error_for_ee);
846 CancelAlarm((unsigned int (*)(void *))stm_ee_read_timeout_alarm_cb, &g_cdvdstm_curclk_ee);
847 return;
848 case 1:
849 g_cdvdstm_mode_ee.datapattern = instruct->m_rmode.datapattern;
850 g_cdvdstm_mode_ee.trycount = instruct->m_rmode.trycount;
851 g_cdvdstm_mode_ee.spindlctrl = instruct->m_rmode.spindlctrl;
852 g_cdvdstm_retryerr_ee = 0;
853 break;
854 }
855 posszarg2_bytes = instruct->m_posszarg2 << 11;
856 if ( cmdid == 9 )
857 {
858 if ( sceCdSC(0xFFFFFFFF, &g_cdvdstm_last_error_for_ee) )
859 {
860 CpuSuspendIntr(&state);
861 g_cdvdstm_lsn_ee = instruct->m_posszarg1;
862 for ( i = 0; i < (unsigned int)g_cdvdstm_bankcnt2; i += 1 )
863 {
864 g_cdvdstm_usedmap_ee[i] = 0;
865 }
866 g_cdvdstm_stmstart_ee = 2;
867 CpuResumeIntr(state);
868 *outres_ptr = 1;
869 return;
870 }
871 *outres_ptr = 0;
872 return;
873 }
874 if ( cmdid == 4 )
875 {
876 retryflag = 1;
877 CpuSuspendIntr(&state);
878 CancelAlarm((unsigned int (*)(void *))ee_stream_intr_cb_normal, &g_cdvdstm_curclk_ee);
879 sceCdSC(0, &g_cdvdstm_last_error_for_ee);
880 posszarg2_bytes = 0;
881 cmdid = 1;
882 CpuResumeIntr(state);
883 g_cdvdstm_lsn_ee = instruct->m_posszarg1;
884 g_cdvdstm_bankoffs_ee = 0;
885 g_cdvdstm_bankcur_ee = 0;
886 g_cdvdstm_bankgp_ee = 0;
887 sceCdSync(0);
888 CancelAlarm((unsigned int (*)(void *))stm_ee_read_timeout_alarm_cb, &g_cdvdstm_curclk_ee);
889 }
890 if ( cmdid == 1 )
891 {
892 CpuSuspendIntr(&state);
893 CancelAlarm((unsigned int (*)(void *))ee_stream_intr_cb_normal, &g_cdvdstm_curclk_ee);
894 sceCdSC(0, &g_cdvdstm_last_error_for_ee);
895 CpuResumeIntr(state);
896 retryflag = 1;
897 for ( i = 0; i < (unsigned int)g_cdvdstm_bankcnt2; i += 1 )
898 {
899 g_cdvdstm_usedmap_ee[i] = 0;
900 }
901 g_cdvdstm_lsn_ee = instruct->m_posszarg1;
902 sceCdSC(0xFFFFFFE9, (int *)&g_cdvdstm_lsn_ee);
903 g_cdvdstm_bankoffs_ee = 0;
904 g_cdvdstm_bankcur_ee = 0;
905 sceCdSync(0);
906 CancelAlarm((unsigned int (*)(void *))stm_ee_read_timeout_alarm_cb, &g_cdvdstm_curclk_ee);
907 g_cdvdstm_stmstart_ee = 1;
908 sceCdSC(2, &g_cdvdstm_last_error_for_ee);
909 if ( !sceCdNop() )
910 {
911 sceCdSC(0, &g_cdvdstm_last_error_for_ee);
912 *outres_ptr = 0;
913 return;
914 }
915 }
916 posszarg2_bytes_overrun = -1;
917 for ( i = 0; i < posszarg2_bytes; i += posszarg2_bytes_clamped )
918 {
919 unsigned int posszarg2_bytes_remain;
920
921 posszarg2_bytes_remain = posszarg2_bytes - i;
922 if ( !g_cdvdstm_usedmap_ee[g_cdvdstm_bankcur_ee] )
923 {
924 VERBOSE_KPRINTF(
925 1,
926 "CD read buffer over run %d %d %d %d %d gp %d pp %d\n",
927 (u8)g_cdvdstm_usedmap_ee[0],
928 (u8)g_cdvdstm_usedmap_ee[1],
929 (u8)g_cdvdstm_usedmap_ee[2],
930 (u8)g_cdvdstm_usedmap_ee[3],
931 (u8)g_cdvdstm_usedmap_ee[4],
932 g_cdvdstm_bankgp_ee,
933 g_cdvdstm_bankcur_ee);
934 CpuSuspendIntr(&state);
935 bankcur_next_tmp1 = g_cdvdstm_bankcur_ee;
936 g_cdvdstm_bankcur_ee += 1;
937 if ( (unsigned int)g_cdvdstm_bankcur_ee >= (unsigned int)g_cdvdstm_bankcnt2 )
938 g_cdvdstm_bankcur_ee = 0;
939 if ( !g_cdvdstm_usedmap_ee[g_cdvdstm_bankcur_ee] )
940 g_cdvdstm_bankcur_ee = bankcur_next_tmp1;
941 posszarg2_bytes_overrun = posszarg2_bytes - posszarg2_bytes_remain;
942 CpuResumeIntr(state);
943 break;
944 }
945 posszarg2_bytes_clamped = ((unsigned int)(g_cdvdstm_chunksz2 - g_cdvdstm_bankoffs_ee) < posszarg2_bytes_remain) ?
946 (unsigned int)(g_cdvdstm_chunksz2 - g_cdvdstm_bankoffs_ee) :
947 posszarg2_bytes_remain;
948 g_cdvdstm_dmat.dest = ((char *)instruct->m_buffer) + i;
949 g_cdvdstm_dmat.size = posszarg2_bytes_clamped;
950 g_cdvdstm_dmat.attr = 0;
951 g_cdvdstm_dmat.src = (char *)g_cdvdstm_buffer2 + g_cdvdstm_bankcur_ee * g_cdvdstm_chunksz2 + g_cdvdstm_bankoffs_ee;
952 if ( posszarg2_bytes_clamped )
953 {
954 while ( 1 )
955 {
956 CpuSuspendIntr(&state);
957 dmat1 = sceSifSetDma(&g_cdvdstm_dmat, 1);
958 CpuResumeIntr(state);
959 if ( dmat1 )
960 break;
961 DelayThread(500);
962 }
963 g_cdvdstm_bankoffs_ee += posszarg2_bytes_clamped;
964 while ( vsceSifDmaStat(dmat1) >= 0 )
965 ;
966 }
967 if ( (unsigned int)g_cdvdstm_bankoffs_ee >= (unsigned int)g_cdvdstm_chunksz2 )
968 {
969 CpuSuspendIntr(&state);
970 g_cdvdstm_bankoffs_ee = 0;
971 g_cdvdstm_usedmap_ee[g_cdvdstm_bankcur_ee] = 0;
972 bankcur_next_tmp2 = g_cdvdstm_bankcur_ee;
973 g_cdvdstm_bankcur_ee += 1;
974 if ( (unsigned int)g_cdvdstm_bankcur_ee >= (unsigned int)g_cdvdstm_bankcnt2 )
975 g_cdvdstm_bankcur_ee = 0;
976 if ( g_cdvdstm_usedmap_ee[g_cdvdstm_bankcur_ee] && g_cdvdstm_bankgp_ee != g_cdvdstm_bankcur_ee )
977 {
978 CpuResumeIntr(state);
979 }
980 else
981 {
982 g_cdvdstm_bankcur_ee = bankcur_next_tmp2;
983 CpuResumeIntr(state);
984 VERBOSE_KPRINTF(
985 1,
986 "CD read buffer over run %d %d %d %d %d gp %d pp %d\n",
987 (u8)g_cdvdstm_usedmap_ee[0],
988 (u8)g_cdvdstm_usedmap_ee[1],
989 (u8)g_cdvdstm_usedmap_ee[2],
990 (u8)g_cdvdstm_usedmap_ee[3],
991 (u8)g_cdvdstm_usedmap_ee[4],
992 g_cdvdstm_bankgp_ee,
993 g_cdvdstm_bankcur_ee);
994 posszarg2_bytes_overrun = posszarg2_bytes - (posszarg2_bytes_remain - posszarg2_bytes_clamped);
995 break;
996 }
997 }
998 }
999 if ( posszarg2_bytes_overrun == -1 )
1000 posszarg2_bytes_overrun = posszarg2_bytes;
1001 outres_tmp2 = (retryflag) ? 1 : (posszarg2_bytes_overrun / 0x800);
1002 if ( !retryflag )
1003 {
1004 if ( sceCdSC(0xFFFFFFFF, &g_cdvdstm_last_error_for_ee) != 2 && !outres_tmp2 && !g_cdvdstm_retryerr_ee )
1005 g_cdvdstm_retryerr_ee = 273;
1006 if ( g_cdvdstm_retryerr_ee )
1007 {
1008 outres_tmp2 = (u16)outres_tmp2 | (g_cdvdstm_retryerr_ee << 16);
1009 g_cdvdstm_retryerr_ee = 0;
1010 }
1011 }
1012 *outres_ptr = outres_tmp2;
1013 return;
1014}
1015
1016static unsigned int ee_stream_intr_cb_normal(void *userdata)
1017{
1018 int scres_unused;
1019
1020 (void)userdata;
1021
1022 VERBOSE_KPRINTF(1, "Intr EE Stm Read call\n");
1023 iCancelAlarm((unsigned int (*)(void *))stm_ee_read_timeout_alarm_cb, &g_cdvdstm_curclk_ee);
1024 iCancelAlarm((unsigned int (*)(void *))ee_stream_intr_cb_normal, &g_cdvdstm_curclk_ee);
1025 sceCdSC(0xFFFFFFFF, &g_cdvdstm_last_error_for_ee);
1026 if ( !g_cdvdstm_last_error_for_ee )
1027 {
1028#ifdef CDVD_VARIANT_XOSD
1029 switch ( sceCdSC(0xFFFFFFDA, &scres_unused) )
1030#else
1031 switch ( sceCdGetDiskType() )
1032#endif
1033 {
1034 case SCECdPSCD:
1035 case SCECdPSCDDA:
1036 case SCECdPS2CD:
1037 case SCECdPS2CDDA:
1038 case SCECdPS2DVD:
1039 break;
1040 default:
1041 g_cdvdstm_last_error_for_ee = SCECdErREADCF;
1042 break;
1043 }
1044 }
1045 g_cdvdstm_curclk_ee.hi = 0;
1046 if ( g_cdvdstm_stmstart_ee )
1047 g_cdvdstm_retrycnt_ee_normal = 0;
1048 g_cdvdstm_curclk_ee.lo = (g_cdvdstm_stmstart_ee || g_cdvdstm_last_error_for_ee || g_cdvdstm_retrycnt_ee_normal) ?
1049 0x20f58000 :
1050 (0x9000 * sceCdSC(0xFFFFFFEF, &scres_unused));
1051 if ( g_cdvdstm_last_error_for_ee )
1052 {
1053 VERBOSE_KPRINTF(
1054 1,
1055 "EE Stream read LBN= %d Error code= 0x%02x retry= %d\n",
1056 g_cdvdstm_readlbn_ee_normal,
1057 g_cdvdstm_last_error_for_ee,
1058 g_cdvdstm_retrycnt_ee_normal);
1059 if ( g_cdvdstm_last_error_for_ee == SCECdErREAD || g_cdvdstm_last_error_for_ee == SCECdErABRT )
1060 {
1061 if ( g_cdvdstm_retrycnt_ee_normal )
1062 {
1063 VERBOSE_KPRINTF(1, "On Retry retry %d err %08x\n", g_cdvdstm_retrycnt_ee_normal, g_cdvdstm_last_error_for_ee);
1064 }
1065 g_cdvdstm_retrycnt_ee_normal = 3;
1066 }
1067 else
1068 {
1069 g_cdvdstm_retrycnt_ee_normal = 1;
1070 }
1071 g_cdvdstm_retryerr_ee = g_cdvdstm_last_error_for_ee;
1072 }
1073 if ( g_cdvdstm_retrycnt_ee_normal )
1074 {
1075 g_cdvdstm_retrycnt_ee_normal -= 1;
1076 if ( sceCdRE(
1077 ((unsigned int)g_cdvdstm_readlbn_ee_normal >= (unsigned int)(0x10 * g_cdvdstm_retrycnt_ee_normal)) ?
1078 (g_cdvdstm_readlbn_ee_normal - 0x10 * g_cdvdstm_retrycnt_ee_normal) :
1079 (g_cdvdstm_readlbn_ee_normal + 0x10 * g_cdvdstm_retrycnt_ee_normal),
1080 g_cdvdstm_sectorcount2,
1081 (char *)g_cdvdstm_buffer2 + g_cdvdstm_bankgp_ee * g_cdvdstm_chunksz2,
1082 &g_cdvdstm_mode_ee) )
1083 {
1084 iSetAlarm(&g_cdvdstm_curclk_ee, (unsigned int (*)(void *))stm_ee_read_timeout_alarm_cb, &g_cdvdstm_curclk_ee);
1085 }
1086 else
1087 {
1088 VERBOSE_KPRINTF(1, "Stm Read Call fail\n");
1089 g_cdvdstm_curclk_ee.lo = 0x708000;
1090 if (
1091 iSetAlarm(&g_cdvdstm_curclk_ee, (unsigned int (*)(void *))ee_stream_intr_cb_normal, &g_cdvdstm_curclk_ee)
1092 && !sceCdNop() )
1093 {
1094 sceCdSC(0, &g_cdvdstm_last_error_for_ee);
1095 }
1096 g_cdvdstm_retrycnt_ee_normal += 1;
1097 }
1098 }
1099 else
1100 {
1101 int gptmp;
1102
1103 if ( !g_cdvdstm_stmstart_ee )
1104 {
1105 g_cdvdstm_usedmap_ee[g_cdvdstm_bankgp_ee] = 1;
1106 gptmp = g_cdvdstm_bankgp_ee;
1107 g_cdvdstm_bankgp_ee += 1;
1108 if ( (unsigned int)g_cdvdstm_bankgp_ee >= (unsigned int)g_cdvdstm_bankcnt2 )
1109 g_cdvdstm_bankgp_ee = 0;
1110 }
1111 if (
1112 !g_cdvdstm_stmstart_ee
1113 && (g_cdvdstm_usedmap_ee[g_cdvdstm_bankgp_ee] || g_cdvdstm_bankcur_ee == g_cdvdstm_bankgp_ee) )
1114 {
1115 g_cdvdstm_bankgp_ee = gptmp;
1116 g_cdvdstm_usedmap_ee[gptmp] = 0;
1117 VERBOSE_KPRINTF(
1118 1,
1119 "read Full %d %d %d %d %d gp %d pp %d spn %d\n",
1120 (u8)g_cdvdstm_usedmap_ee[0],
1121 (u8)g_cdvdstm_usedmap_ee[1],
1122 (u8)g_cdvdstm_usedmap_ee[2],
1123 (u8)g_cdvdstm_usedmap_ee[3],
1124 (u8)g_cdvdstm_usedmap_ee[4],
1125 g_cdvdstm_bankgp_ee,
1126 g_cdvdstm_bankcur_ee,
1127 g_cdvdstm_mode_ee.spindlctrl);
1128 g_cdvdstm_curclk_ee.lo = 0x48000;
1129 if (
1130 iSetAlarm(&g_cdvdstm_curclk_ee, (unsigned int (*)(void *))ee_stream_intr_cb_normal, &g_cdvdstm_curclk_ee)
1131 && !sceCdNop() )
1132 {
1133 sceCdSC(0, &g_cdvdstm_last_error_for_ee);
1134 }
1135 }
1136 else
1137 {
1138 if ( g_cdvdstm_stmstart_ee == 2 )
1139 {
1140 unsigned int i;
1141
1142 g_cdvdstm_bankoffs_ee = 0;
1143 g_cdvdstm_bankcur_ee = 0;
1144 g_cdvdstm_bankgp_ee = 0;
1145 for ( i = 0; i < (unsigned int)g_cdvdstm_bankcnt2; i += 1 )
1146 g_cdvdstm_usedmap_ee[i] = 0;
1147 }
1148 g_cdvdstm_stmstart_ee = 0;
1149 g_cdvdstm_readlbn_ee_normal = g_cdvdstm_lsn_ee;
1150 if ( sceCdRE(
1151 g_cdvdstm_lsn_ee,
1152 g_cdvdstm_sectorcount2,
1153 (char *)g_cdvdstm_buffer2 + g_cdvdstm_bankgp_ee * g_cdvdstm_chunksz2,
1154 &g_cdvdstm_mode_ee) )
1155 {
1156 iSetAlarm(&g_cdvdstm_curclk_ee, (unsigned int (*)(void *))stm_ee_read_timeout_alarm_cb, &g_cdvdstm_curclk_ee);
1157 }
1158 else
1159 {
1160 VERBOSE_KPRINTF(1, "Stm Read Call1 fail\n");
1161 g_cdvdstm_curclk_ee.lo = 0x708000;
1162 if (
1163 iSetAlarm(&g_cdvdstm_curclk_ee, (unsigned int (*)(void *))ee_stream_intr_cb_normal, &g_cdvdstm_curclk_ee)
1164 && !sceCdNop() )
1165 {
1166 sceCdSC(0, &g_cdvdstm_last_error_for_ee);
1167 }
1168 g_cdvdstm_retrycnt_ee_normal = 1;
1169 }
1170 g_cdvdstm_lsn_ee += g_cdvdstm_sectorcount2;
1171 }
1172 }
1173 return 0;
1174}
1175
1176static void ee_stream_handler_cdda(cdrom_stm_devctl_t *instruct, int inbuf_len, int *outres_ptr)
1177{
1178 u32 cmdid;
1179 u32 posszarg2_bytes;
1180 int retryflag;
1181 int bankcur_tmp;
1182 u32 chunks_sectors;
1183 int bankcur_next_tmp1;
1184 int posszarg2_bytes_clamped;
1185 int dmat2;
1186 int bankcur_next_tmp2;
1187 int posszarg2_overrun_chunks2;
1188 unsigned int posszarg2_bytes_overrun;
1189 int state;
1190 unsigned int i;
1191
1192 (void)inbuf_len;
1193
1194 cmdid = instruct->m_cmdid;
1195 posszarg2_bytes = instruct->m_posszarg2 * g_cdvdstm_usedchunksize2;
1196 retryflag = 0;
1197 if ( g_cdvdstm_stmstart_ee == 2 && (cmdid != 9 && cmdid != 3) )
1198 {
1199 *outres_ptr = 0;
1200 return;
1201 }
1202 switch ( cmdid )
1203 {
1204 case 8:
1205 sceCdSC(2, &g_cdvdstm_last_error_for_ee);
1206 if ( sceCdNop() )
1207 {
1208 *outres_ptr = 1;
1209 return;
1210 }
1211 sceCdSC(0, &g_cdvdstm_last_error_for_ee);
1212 *outres_ptr = 0;
1213 return;
1214 case 7:
1215 CpuSuspendIntr(&state);
1216 CancelAlarm((unsigned int (*)(void *))ee_stream_intr_cb_cdda, &g_cdvdstm_curclk_ee);
1217 sceCdSC(0, &g_cdvdstm_last_error_for_ee);
1218 CpuResumeIntr(state);
1219 sceCdSync(0);
1220 *outres_ptr = 1;
1221 CancelAlarm((unsigned int (*)(void *))stm_ee_read_timeout_alarm_cb, &g_cdvdstm_curclk_ee);
1222 return;
1223 case 6:
1224 bankcur_tmp = g_cdvdstm_bankcur_ee;
1225 if ( !g_cdvdstm_usedmap_ee[bankcur_tmp] )
1226 {
1227 bankcur_tmp += 1;
1228 if ( (unsigned int)bankcur_tmp >= (unsigned int)g_cdvdstm_bankcnt2 )
1229 bankcur_tmp = 0;
1230 if ( !g_cdvdstm_usedmap_ee[bankcur_tmp] )
1231 bankcur_tmp = g_cdvdstm_bankcur_ee;
1232 }
1233 for ( i = 0; (i < (unsigned int)g_cdvdstm_bankcnt2) && g_cdvdstm_usedmap_ee[bankcur_tmp]
1234 && (g_cdvdstm_bankgp_ee != bankcur_tmp);
1235 i += 1 )
1236 {
1237 bankcur_tmp += 1;
1238 if ( (unsigned int)(bankcur_tmp) >= (unsigned int)g_cdvdstm_bankcnt2 )
1239 bankcur_tmp = 0;
1240 }
1241 if ( !g_cdvdstm_usedchunksize2 )
1242 __builtin_trap();
1243 *outres_ptr = i * (g_cdvdstm_chunksz2 / (unsigned int)g_cdvdstm_usedchunksize2);
1244 return;
1245 case 5:
1246 sceCdstm1Cb((void (*)(int))ee_stream_intr_cb_cdda_thunk);
1247 switch ( instruct->m_rmode.datapattern )
1248 {
1249 case SCECdSecS2368:
1250 g_cdvdstm_usedchunksize2 = 2368;
1251 break;
1252 case SCECdSecS2448:
1253 g_cdvdstm_usedchunksize2 = 2448;
1254 break;
1255 case SCECdSecS2352:
1256 default:
1257 g_cdvdstm_usedchunksize2 = 0x930;
1258 break;
1259 }
1260 if ( !instruct->m_posszarg2 )
1261 __builtin_trap();
1262 chunks_sectors = instruct->m_posszarg1 / instruct->m_posszarg2;
1263 g_cdvdstm_bufsz2 = instruct->m_posszarg1;
1264 g_cdvdstm_sectorcount2 = chunks_sectors;
1265 g_cdvdstm_chunksz2 = chunks_sectors * g_cdvdstm_usedchunksize2;
1266 g_cdvdstm_buffer2 = (char *)instruct->m_buffer;
1267 g_cdvdstm_bankcnt2 = instruct->m_posszarg2;
1268 PRINTF(
1269 "DA Stream Buffer 1Bank %dbyte %dbanks %dbyte used\n",
1270 (int)(chunks_sectors * g_cdvdstm_usedchunksize2),
1271 (int)instruct->m_posszarg2,
1272 (int)(chunks_sectors * g_cdvdstm_usedchunksize2 * instruct->m_posszarg2));
1273 *outres_ptr = 1;
1274 return;
1275 case 3:
1276 CpuSuspendIntr(&state);
1277 g_cdvdstm_stmstart_ee = 0;
1278 CancelAlarm((unsigned int (*)(void *))ee_stream_intr_cb_cdda, &g_cdvdstm_curclk_ee);
1279 sceCdSC(0, &g_cdvdstm_last_error_for_ee);
1280 CpuResumeIntr(state);
1281 sceCdBreak();
1282 for ( i = 0; i < (unsigned int)g_cdvdstm_bankcnt2; i += 1 )
1283 {
1284 g_cdvdstm_usedmap_ee[i] = 0;
1285 }
1286 g_cdvdstm_bankoffs_ee = 0;
1287 g_cdvdstm_bankcur_ee = 0;
1288 g_cdvdstm_bankgp_ee = 0;
1289 *outres_ptr = 1;
1290 sceCdSync(0);
1291 g_cdvdstm_last_error_for_ee = 0;
1292 sceCdSC(0xFFFFFFFE, &g_cdvdstm_last_error_for_ee);
1293 CancelAlarm((unsigned int (*)(void *))stm_ee_read_timeout_alarm_cb, &g_cdvdstm_curclk_ee);
1294 return;
1295 case 1:
1296 g_cdvdstm_mode_ee.datapattern = instruct->m_rmode.datapattern;
1297 g_cdvdstm_mode_ee.trycount = instruct->m_rmode.trycount;
1298 g_cdvdstm_mode_ee.spindlctrl = instruct->m_rmode.spindlctrl;
1299 g_cdvdstm_retryerr_ee = 0;
1300 break;
1301 }
1302 if ( cmdid == 9 )
1303 {
1304 if ( sceCdSC(0xFFFFFFFF, &g_cdvdstm_last_error_for_ee) )
1305 {
1306 CpuSuspendIntr(&state);
1307 g_cdvdstm_lsn_ee = instruct->m_posszarg1;
1308 for ( i = 0; i < (unsigned int)g_cdvdstm_bankcnt2; i += 1 )
1309 {
1310 g_cdvdstm_usedmap_ee[i] = 0;
1311 }
1312 g_cdvdstm_stmstart_ee = 2;
1313 CpuResumeIntr(state);
1314 *outres_ptr = 1;
1315 return;
1316 }
1317 *outres_ptr = 0;
1318 return;
1319 }
1320 if ( cmdid == 4 )
1321 {
1322 retryflag = 1;
1323 CpuSuspendIntr(&state);
1324 CancelAlarm((unsigned int (*)(void *))ee_stream_intr_cb_cdda, &g_cdvdstm_curclk_ee);
1325 sceCdSC(0, &g_cdvdstm_last_error_for_ee);
1326 posszarg2_bytes = 0;
1327 cmdid = 1;
1328 CpuResumeIntr(state);
1329 g_cdvdstm_lsn_ee = instruct->m_posszarg1;
1330 g_cdvdstm_bankoffs_ee = 0;
1331 g_cdvdstm_bankcur_ee = 0;
1332 g_cdvdstm_bankgp_ee = 0;
1333 sceCdSync(0);
1334 CancelAlarm((unsigned int (*)(void *))stm_ee_read_timeout_alarm_cb, &g_cdvdstm_curclk_ee);
1335 }
1336 if ( cmdid == 1 )
1337 {
1338 signed int posszarg2_chunks;
1339
1340 CpuSuspendIntr(&state);
1341 CancelAlarm((unsigned int (*)(void *))ee_stream_intr_cb_cdda, &g_cdvdstm_curclk_ee);
1342 sceCdSC(0, &g_cdvdstm_last_error_for_ee);
1343 CpuResumeIntr(state);
1344 retryflag = 1;
1345 for ( i = 0; i < (unsigned int)g_cdvdstm_bankcnt2; i += 1 )
1346 {
1347 g_cdvdstm_usedmap_ee[i] = 0;
1348 }
1349 g_cdvdstm_lsn_ee = instruct->m_posszarg1;
1350 g_cdvdstm_bankoffs_ee = 0;
1351 g_cdvdstm_bankcur_ee = 0;
1352 sceCdSync(0);
1353 CancelAlarm((unsigned int (*)(void *))stm_ee_read_timeout_alarm_cb, &g_cdvdstm_curclk_ee);
1354 if ( !g_cdvdstm_chunksz2 )
1355 __builtin_trap();
1356 posszarg2_chunks = (posszarg2_bytes / g_cdvdstm_chunksz2) + (!!(posszarg2_bytes % g_cdvdstm_chunksz2));
1357 for ( g_cdvdstm_bankgp_ee = 0; g_cdvdstm_bankgp_ee < posszarg2_chunks; g_cdvdstm_bankgp_ee += 1 )
1358 {
1359 int outres_tmp2;
1360
1361 outres_tmp2 = sceCdReadCDDA(g_cdvdstm_lsn_ee, g_cdvdstm_sectorcount2, g_cdvdstm_buffer2, &g_cdvdstm_mode_ee);
1362 sceCdSync(3);
1363 sceCdSC(0xFFFFFFFF, &g_cdvdstm_last_error_for_ee);
1364 if ( g_cdvdstm_last_error_for_ee || !outres_tmp2 )
1365 {
1366 sceCdSC(0, &g_cdvdstm_last_error_for_ee);
1367 *outres_ptr = 0;
1368 return;
1369 }
1370 g_cdvdstm_lsn_ee += g_cdvdstm_sectorcount2;
1371 g_cdvdstm_usedmap_ee[g_cdvdstm_bankgp_ee] = 1;
1372 }
1373 g_cdvdstm_stmstart_ee = 1;
1374 sceCdSC(2, &g_cdvdstm_last_error_for_ee);
1375 if ( !sceCdNop() )
1376 {
1377 sceCdSC(0, &g_cdvdstm_last_error_for_ee);
1378 *outres_ptr = 0;
1379 return;
1380 }
1381 }
1382 posszarg2_bytes_overrun = -1;
1383 for ( i = 0; i < posszarg2_bytes; i += posszarg2_bytes_clamped )
1384 {
1385 unsigned int posszarg2_bytes_remain;
1386
1387 posszarg2_bytes_remain = posszarg2_bytes - i;
1388 if ( !g_cdvdstm_usedmap_ee[g_cdvdstm_bankcur_ee] )
1389 {
1390 VERBOSE_KPRINTF(
1391 1,
1392 "CD read buffer over run %d %d %d %d %d gp %d pp %d\n",
1393 (u8)g_cdvdstm_usedmap_ee[0],
1394 (u8)g_cdvdstm_usedmap_ee[1],
1395 (u8)g_cdvdstm_usedmap_ee[2],
1396 (u8)g_cdvdstm_usedmap_ee[3],
1397 (u8)g_cdvdstm_usedmap_ee[4],
1398 g_cdvdstm_bankgp_ee,
1399 g_cdvdstm_bankcur_ee);
1400 CpuSuspendIntr(&state);
1401 bankcur_next_tmp1 = g_cdvdstm_bankcur_ee;
1402 g_cdvdstm_bankcur_ee += 1;
1403 if ( (unsigned int)g_cdvdstm_bankcur_ee >= (unsigned int)g_cdvdstm_bankcnt2 )
1404 g_cdvdstm_bankcur_ee = 0;
1405 if ( !g_cdvdstm_usedmap_ee[g_cdvdstm_bankcur_ee] )
1406 g_cdvdstm_bankcur_ee = bankcur_next_tmp1;
1407 posszarg2_bytes_overrun = posszarg2_bytes - posszarg2_bytes_remain;
1408 CpuResumeIntr(state);
1409 break;
1410 }
1411 posszarg2_bytes_clamped = ((unsigned int)(g_cdvdstm_chunksz2 - g_cdvdstm_bankoffs_ee) < posszarg2_bytes_remain) ?
1412 (unsigned int)(g_cdvdstm_chunksz2 - g_cdvdstm_bankoffs_ee) :
1413 posszarg2_bytes_remain;
1414 g_cdvdstm_dmat2.dest = ((char *)instruct->m_buffer) + i;
1415 g_cdvdstm_dmat2.size = posszarg2_bytes_clamped;
1416 g_cdvdstm_dmat2.attr = 0;
1417 g_cdvdstm_dmat2.src = (char *)g_cdvdstm_buffer2 + g_cdvdstm_bankcur_ee * g_cdvdstm_chunksz2 + g_cdvdstm_bankoffs_ee;
1418 if ( posszarg2_bytes_clamped )
1419 {
1420 while ( 1 )
1421 {
1422 CpuSuspendIntr(&state);
1423 dmat2 = sceSifSetDma(&g_cdvdstm_dmat2, 1);
1424 CpuResumeIntr(state);
1425 if ( dmat2 )
1426 break;
1427 DelayThread(500);
1428 }
1429 g_cdvdstm_bankoffs_ee += posszarg2_bytes_clamped;
1430 while ( vsceSifDmaStat(dmat2) >= 0 )
1431 ;
1432 }
1433 if ( (unsigned int)g_cdvdstm_bankoffs_ee >= (unsigned int)g_cdvdstm_chunksz2 )
1434 {
1435 CpuSuspendIntr(&state);
1436 g_cdvdstm_bankoffs_ee = 0;
1437 g_cdvdstm_usedmap_ee[g_cdvdstm_bankcur_ee] = 0;
1438 bankcur_next_tmp2 = g_cdvdstm_bankcur_ee;
1439 g_cdvdstm_bankcur_ee += 1;
1440 if ( (unsigned int)g_cdvdstm_bankcur_ee >= (unsigned int)g_cdvdstm_bankcnt2 )
1441 g_cdvdstm_bankcur_ee = 0;
1442 if ( g_cdvdstm_usedmap_ee[g_cdvdstm_bankcur_ee] && g_cdvdstm_bankgp_ee != g_cdvdstm_bankcur_ee )
1443 {
1444 CpuResumeIntr(state);
1445 }
1446 else
1447 {
1448 g_cdvdstm_bankcur_ee = bankcur_next_tmp2;
1449 CpuResumeIntr(state);
1450 VERBOSE_KPRINTF(
1451 1,
1452 "CD read buffer over run %d %d %d %d %d gp %d pp %d\n",
1453 (u8)g_cdvdstm_usedmap_ee[0],
1454 (u8)g_cdvdstm_usedmap_ee[1],
1455 (u8)g_cdvdstm_usedmap_ee[2],
1456 (u8)g_cdvdstm_usedmap_ee[3],
1457 (u8)g_cdvdstm_usedmap_ee[4],
1458 g_cdvdstm_bankgp_ee,
1459 g_cdvdstm_bankcur_ee);
1460 posszarg2_bytes_overrun = posszarg2_bytes - (posszarg2_bytes_remain - posszarg2_bytes_clamped);
1461 break;
1462 }
1463 }
1464 }
1465 if ( posszarg2_bytes_overrun == 0xFFFFFFFF )
1466 posszarg2_bytes_overrun = posszarg2_bytes;
1467 if ( !g_cdvdstm_usedchunksize2 )
1468 __builtin_trap();
1469 posszarg2_overrun_chunks2 = posszarg2_bytes_overrun / g_cdvdstm_usedchunksize2;
1470 if ( retryflag )
1471 {
1472 *outres_ptr = 1;
1473 return;
1474 }
1475 if ( sceCdSC(0xFFFFFFFF, &g_cdvdstm_last_error_for_ee) != 2 && !posszarg2_overrun_chunks2 && !g_cdvdstm_retryerr_ee )
1476 g_cdvdstm_retryerr_ee = 273;
1477 if ( g_cdvdstm_retryerr_ee )
1478 {
1479 posszarg2_overrun_chunks2 = (u16)posszarg2_overrun_chunks2 | (g_cdvdstm_retryerr_ee << 16);
1480 g_cdvdstm_retryerr_ee = 0;
1481 }
1482 *outres_ptr = posszarg2_overrun_chunks2;
1483}
1484
1485static unsigned int ee_stream_intr_cb_cdda(void *userdata)
1486{
1487 int scres_unused;
1488
1489 (void)userdata;
1490
1491 VERBOSE_KPRINTF(1, "Intr EE DA Stm Read call\n");
1492 iCancelAlarm((unsigned int (*)(void *))stm_ee_read_timeout_alarm_cb, &g_cdvdstm_curclk_ee);
1493 iCancelAlarm((unsigned int (*)(void *))ee_stream_intr_cb_cdda, &g_cdvdstm_curclk_ee);
1494 sceCdSC(0xFFFFFFFF, &g_cdvdstm_last_error_for_ee);
1495 if ( !g_cdvdstm_last_error_for_ee )
1496 {
1497#ifdef CDVD_VARIANT_XOSD
1498 switch ( sceCdSC(0xFFFFFFDA, &scres_unused) )
1499#else
1500 switch ( sceCdGetDiskType() )
1501#endif
1502 {
1503 case SCECdPSCDDA:
1504 case SCECdPS2CDDA:
1505 case 0x21:
1506 case SCECdCDDA:
1507 break;
1508 default:
1509 g_cdvdstm_last_error_for_ee = SCECdErREADCF;
1510 break;
1511 }
1512 }
1513 g_cdvdstm_curclk_ee.hi = 0;
1514 if ( g_cdvdstm_stmstart_ee )
1515 g_cdvdstm_retrycnt_ee_cdda = 0;
1516 g_cdvdstm_curclk_ee.lo = (g_cdvdstm_stmstart_ee || g_cdvdstm_last_error_for_ee || g_cdvdstm_retrycnt_ee_cdda) ?
1517 0x20f58000 :
1518 (0x9000 * sceCdSC(0xFFFFFFEF, &scres_unused));
1519 if ( g_cdvdstm_last_error_for_ee )
1520 {
1521 VERBOSE_KPRINTF(
1522 1,
1523 "EE Stream read LBN= %d Error code= 0x%02x retry= %d\n",
1524 g_cdvdstm_readlbn_ee_cdda,
1525 g_cdvdstm_last_error_for_ee,
1526 g_cdvdstm_retrycnt_ee_cdda);
1527 if ( g_cdvdstm_last_error_for_ee == SCECdErREAD || g_cdvdstm_last_error_for_ee == SCECdErABRT )
1528 {
1529 if ( g_cdvdstm_retrycnt_ee_cdda )
1530 {
1531 VERBOSE_KPRINTF(1, "On Retry retry %d err %08x\n", g_cdvdstm_retrycnt_ee_cdda, g_cdvdstm_last_error_for_ee);
1532 }
1533 g_cdvdstm_retrycnt_ee_cdda = 4;
1534 }
1535 else
1536 {
1537 g_cdvdstm_retrycnt_ee_cdda = 1;
1538 }
1539 g_cdvdstm_retryerr_ee = g_cdvdstm_last_error_for_ee;
1540 }
1541 else
1542 {
1543 g_cdvdstm_retrycnt_ee_cdda = 0;
1544 }
1545 if ( g_cdvdstm_retrycnt_ee_cdda )
1546 {
1547 g_cdvdstm_retrycnt_ee_cdda -= 1;
1548 if (
1549 !g_cdvdstm_retrycnt_ee_cdda
1550 && (g_cdvdstm_last_error_for_ee == SCECdErREAD || g_cdvdstm_last_error_for_ee == SCECdErABRT) )
1551 {
1552 g_cdvdstm_readlbn_ee_cdda =
1553 g_cdvdstm_lsn_ee + ((g_cdvdstm_sectorcount2 < 0x1D) ? (0x1D - g_cdvdstm_sectorcount2) : 0);
1554 g_cdvdstm_lsn_ee = g_cdvdstm_readlbn_ee_cdda + g_cdvdstm_sectorcount2;
1555 }
1556 if ( sceCdReadCDDA(
1557 g_cdvdstm_readlbn_ee_cdda,
1558 g_cdvdstm_sectorcount2,
1559 (char *)g_cdvdstm_buffer2 + g_cdvdstm_bankgp_ee * g_cdvdstm_chunksz2,
1560 &g_cdvdstm_mode_ee) )
1561 {
1562 iSetAlarm(&g_cdvdstm_curclk_ee, (unsigned int (*)(void *))stm_ee_read_timeout_alarm_cb, &g_cdvdstm_curclk_ee);
1563 }
1564 else
1565 {
1566 VERBOSE_KPRINTF(1, "Stm Read Call fail\n");
1567 g_cdvdstm_curclk_ee.lo = 0x708000;
1568 if (
1569 iSetAlarm(&g_cdvdstm_curclk_ee, (unsigned int (*)(void *))ee_stream_intr_cb_cdda, &g_cdvdstm_curclk_ee)
1570 && !sceCdNop() )
1571 {
1572 sceCdSC(0, &g_cdvdstm_last_error_for_ee);
1573 }
1574 g_cdvdstm_retrycnt_ee_cdda += 1;
1575 }
1576 }
1577 else
1578 {
1579 int gptmp;
1580
1581 if ( !g_cdvdstm_stmstart_ee )
1582 {
1583 g_cdvdstm_usedmap_ee[g_cdvdstm_bankgp_ee] = 1;
1584 gptmp = g_cdvdstm_bankgp_ee;
1585 g_cdvdstm_bankgp_ee += 1;
1586 if ( (unsigned int)g_cdvdstm_bankgp_ee >= (unsigned int)g_cdvdstm_bankcnt2 )
1587 g_cdvdstm_bankgp_ee = 0;
1588 }
1589 if (
1590 !g_cdvdstm_stmstart_ee
1591 && (g_cdvdstm_usedmap_ee[g_cdvdstm_bankgp_ee] || g_cdvdstm_bankcur_ee == g_cdvdstm_bankgp_ee) )
1592 {
1593 g_cdvdstm_bankgp_ee = gptmp;
1594 g_cdvdstm_usedmap_ee[gptmp] = 0;
1595 VERBOSE_KPRINTF(
1596 1,
1597 "read Full %d %d %d %d %d gp %d pp %d spn %d\n",
1598 (u8)g_cdvdstm_usedmap_ee[0],
1599 (u8)g_cdvdstm_usedmap_ee[1],
1600 (u8)g_cdvdstm_usedmap_ee[2],
1601 (u8)g_cdvdstm_usedmap_ee[3],
1602 (u8)g_cdvdstm_usedmap_ee[4],
1603 g_cdvdstm_bankgp_ee,
1604 g_cdvdstm_bankcur_ee,
1605 g_cdvdstm_mode_ee.spindlctrl);
1606 g_cdvdstm_curclk_ee.lo = 0x48000;
1607 if (
1608 iSetAlarm(&g_cdvdstm_curclk_ee, (unsigned int (*)(void *))ee_stream_intr_cb_cdda, &g_cdvdstm_curclk_ee)
1609 && !sceCdNop() )
1610 {
1611 sceCdSC(0, &g_cdvdstm_last_error_for_ee);
1612 }
1613 }
1614 else
1615 {
1616 if ( g_cdvdstm_stmstart_ee == 2 )
1617 {
1618 unsigned int i;
1619
1620 g_cdvdstm_bankoffs_ee = 0;
1621 g_cdvdstm_bankcur_ee = 0;
1622 g_cdvdstm_bankgp_ee = 0;
1623 for ( i = 0; i < (unsigned int)g_cdvdstm_bankcnt2; i += 1 )
1624 g_cdvdstm_usedmap_ee[i] = 0;
1625 }
1626 g_cdvdstm_stmstart_ee = 0;
1627 g_cdvdstm_readlbn_ee_cdda = g_cdvdstm_lsn_ee;
1628 if ( sceCdReadCDDA(
1629 g_cdvdstm_lsn_ee,
1630 g_cdvdstm_sectorcount2,
1631 (char *)g_cdvdstm_buffer2 + g_cdvdstm_bankgp_ee * g_cdvdstm_chunksz2,
1632 &g_cdvdstm_mode_ee) )
1633 {
1634 iSetAlarm(&g_cdvdstm_curclk_ee, (unsigned int (*)(void *))stm_ee_read_timeout_alarm_cb, &g_cdvdstm_curclk_ee);
1635 }
1636 else
1637 {
1638 VERBOSE_KPRINTF(1, "Stm Read Call1 fail\n");
1639 g_cdvdstm_curclk_ee.lo = 0x708000;
1640 if (
1641 iSetAlarm(&g_cdvdstm_curclk_ee, (unsigned int (*)(void *))ee_stream_intr_cb_cdda, &g_cdvdstm_curclk_ee)
1642 && !sceCdNop() )
1643 {
1644 sceCdSC(0, &g_cdvdstm_last_error_for_ee);
1645 }
1646 g_cdvdstm_retrycnt_ee_cdda = 1;
1647 }
1648 g_cdvdstm_lsn_ee += g_cdvdstm_sectorcount2;
1649 }
1650 }
1651 return 0;
1652}
1653
1654// clang-format off
1655__asm__ (
1656 "\t" ".set push" "\n"
1657 "\t" ".set noat" "\n"
1658 "\t" ".set noreorder" "\n"
1659 "\t" ".global optimized_memcpy" "\n"
1660 "\t" "optimized_memcpy:" "\n"
1661 "\t" " srl $a3, $a2, 2" "\n"
1662 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
1663 "\t" " or $a3, $a0, $a1" "\n"
1664 "\t" " andi $a3, $a3, 0x3" "\n"
1665 "\t" " bnez $a3, .Loptimized_memcpy_3" "\n"
1666 "\t" " nop" "\n"
1667 "\t" " srl $a3, $a2, 2" "\n"
1668 "\t" " addiu $at, $zero, 0xC" "\n"
1669 "\t" " div $zero, $a3, $at" "\n"
1670 "\t" " mflo $a3" "\n"
1671 "\t" " mfhi $v1" "\n"
1672 "\t" " beqz $v1, .Loptimized_memcpy_2" "\n"
1673 "\t" " nop" "\n"
1674 "\t" ".Loptimized_memcpy_1:" "\n"
1675 "\t" " lw $v0, 0x0($a1)" "\n"
1676 "\t" " addiu $v1, $v1, -0x1" "\n"
1677 "\t" " sw $v0, 0x0($a0)" "\n"
1678 "\t" " addiu $a1, $a1, 0x4" "\n"
1679 "\t" " bnez $v1, .Loptimized_memcpy_1" "\n"
1680 "\t" " addiu $a0, $a0, 0x4" "\n"
1681 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
1682 "\t" " nop" "\n"
1683 "\t" ".Loptimized_memcpy_2:" "\n"
1684 "\t" " lw $v0, 0x0($a1)" "\n"
1685 "\t" " lw $v1, 0x4($a1)" "\n"
1686 "\t" " lw $t0, 0x8($a1)" "\n"
1687 "\t" " lw $t1, 0xC($a1)" "\n"
1688 "\t" " lw $t2, 0x10($a1)" "\n"
1689 "\t" " lw $t3, 0x14($a1)" "\n"
1690 "\t" " lw $t4, 0x18($a1)" "\n"
1691 "\t" " lw $t5, 0x1C($a1)" "\n"
1692 "\t" " lw $t6, 0x20($a1)" "\n"
1693 "\t" " lw $t7, 0x24($a1)" "\n"
1694 "\t" " lw $t8, 0x28($a1)" "\n"
1695 "\t" " lw $t9, 0x2C($a1)" "\n"
1696 "\t" " addiu $a3, $a3, -0x1" "\n"
1697 "\t" " sw $v0, 0x0($a0)" "\n"
1698 "\t" " sw $v1, 0x4($a0)" "\n"
1699 "\t" " sw $t0, 0x8($a0)" "\n"
1700 "\t" " sw $t1, 0xC($a0)" "\n"
1701 "\t" " sw $t2, 0x10($a0)" "\n"
1702 "\t" " sw $t3, 0x14($a0)" "\n"
1703 "\t" " sw $t4, 0x18($a0)" "\n"
1704 "\t" " sw $t5, 0x1C($a0)" "\n"
1705 "\t" " sw $t6, 0x20($a0)" "\n"
1706 "\t" " sw $t7, 0x24($a0)" "\n"
1707 "\t" " sw $t8, 0x28($a0)" "\n"
1708 "\t" " sw $t9, 0x2C($a0)" "\n"
1709 "\t" " addiu $a1, $a1, 0x30" "\n"
1710 "\t" " bnez $a3, .Loptimized_memcpy_2" "\n"
1711 "\t" " addiu $a0, $a0, 0x30" "\n"
1712 "\t" " j .Loptimized_memcpy_12" "\n"
1713 "\t" " nop" "\n"
1714 "\t" ".Loptimized_memcpy_3:" "\n"
1715 "\t" " andi $a3, $a0, 0x3" "\n"
1716 "\t" " beqz $a3, .Loptimized_memcpy_6" "\n"
1717 "\t" " andi $a3, $a1, 0x3" "\n"
1718 "\t" " beqz $a3, .Loptimized_memcpy_6" "\n"
1719 "\t" " nop" "\n"
1720 "\t" " srl $a3, $a2, 2" "\n"
1721 "\t" " addiu $at, $zero, 0xC" "\n"
1722 "\t" " div $zero, $a3, $at" "\n"
1723 "\t" " mflo $a3" "\n"
1724 "\t" " mfhi $v1" "\n"
1725 "\t" " beqz $v1, .Loptimized_memcpy_5" "\n"
1726 "\t" " nop" "\n"
1727 "\t" ".Loptimized_memcpy_4:" "\n"
1728 "\t" " lwl $v0, 0x3($a1)" "\n"
1729 "\t" " lwr $v0, 0x0($a1)" "\n"
1730 "\t" " addiu $v1, $v1, -0x1" "\n"
1731 "\t" " swl $v0, 0x3($a0)" "\n"
1732 "\t" " swr $v0, 0x0($a0)" "\n"
1733 "\t" " addiu $a1, $a1, 0x4" "\n"
1734 "\t" " bnez $v1, .Loptimized_memcpy_4" "\n"
1735 "\t" " addiu $a0, $a0, 0x4" "\n"
1736 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
1737 "\t" " nop" "\n"
1738 "\t" ".Loptimized_memcpy_5:" "\n"
1739 "\t" " lwl $v0, 0x3($a1)" "\n"
1740 "\t" " lwr $v0, 0x0($a1)" "\n"
1741 "\t" " lwl $v1, 0x7($a1)" "\n"
1742 "\t" " lwr $v1, 0x4($a1)" "\n"
1743 "\t" " lwl $t0, 0xB($a1)" "\n"
1744 "\t" " lwr $t0, 0x8($a1)" "\n"
1745 "\t" " lwl $t1, 0xF($a1)" "\n"
1746 "\t" " lwr $t1, 0xC($a1)" "\n"
1747 "\t" " lwl $t2, 0x13($a1)" "\n"
1748 "\t" " lwr $t2, 0x10($a1)" "\n"
1749 "\t" " lwl $t3, 0x17($a1)" "\n"
1750 "\t" " lwr $t3, 0x14($a1)" "\n"
1751 "\t" " lwl $t4, 0x1B($a1)" "\n"
1752 "\t" " lwr $t4, 0x18($a1)" "\n"
1753 "\t" " lwl $t5, 0x1F($a1)" "\n"
1754 "\t" " lwr $t5, 0x1C($a1)" "\n"
1755 "\t" " lwl $t6, 0x23($a1)" "\n"
1756 "\t" " lwr $t6, 0x20($a1)" "\n"
1757 "\t" " lwl $t7, 0x27($a1)" "\n"
1758 "\t" " lwr $t7, 0x24($a1)" "\n"
1759 "\t" " lwl $t8, 0x2B($a1)" "\n"
1760 "\t" " lwr $t8, 0x28($a1)" "\n"
1761 "\t" " lwl $t9, 0x2F($a1)" "\n"
1762 "\t" " lwr $t9, 0x2C($a1)" "\n"
1763 "\t" " addiu $a3, $a3, -0x1" "\n"
1764 "\t" " swl $v0, 0x3($a0)" "\n"
1765 "\t" " swr $v0, 0x0($a0)" "\n"
1766 "\t" " swl $v1, 0x7($a0)" "\n"
1767 "\t" " swr $v1, 0x4($a0)" "\n"
1768 "\t" " swl $t0, 0xB($a0)" "\n"
1769 "\t" " swr $t0, 0x8($a0)" "\n"
1770 "\t" " swl $t1, 0xF($a0)" "\n"
1771 "\t" " swr $t1, 0xC($a0)" "\n"
1772 "\t" " swl $t2, 0x13($a0)" "\n"
1773 "\t" " swr $t2, 0x10($a0)" "\n"
1774 "\t" " swl $t3, 0x17($a0)" "\n"
1775 "\t" " swr $t3, 0x14($a0)" "\n"
1776 "\t" " swl $t4, 0x1B($a0)" "\n"
1777 "\t" " swr $t4, 0x18($a0)" "\n"
1778 "\t" " swl $t5, 0x1F($a0)" "\n"
1779 "\t" " swr $t5, 0x1C($a0)" "\n"
1780 "\t" " swl $t6, 0x23($a0)" "\n"
1781 "\t" " swr $t6, 0x20($a0)" "\n"
1782 "\t" " swl $t7, 0x27($a0)" "\n"
1783 "\t" " swr $t7, 0x24($a0)" "\n"
1784 "\t" " swl $t8, 0x2B($a0)" "\n"
1785 "\t" " swr $t8, 0x28($a0)" "\n"
1786 "\t" " swl $t9, 0x2F($a0)" "\n"
1787 "\t" " swr $t9, 0x2C($a0)" "\n"
1788 "\t" " addiu $a1, $a1, 0x30" "\n"
1789 "\t" " bnez $a3, .Loptimized_memcpy_5" "\n"
1790 "\t" " addiu $a0, $a0, 0x30" "\n"
1791 "\t" " j .Loptimized_memcpy_12" "\n"
1792 "\t" " nop" "\n"
1793 "\t" ".Loptimized_memcpy_6:" "\n"
1794 "\t" " andi $a3, $a0, 0x3" "\n"
1795 "\t" " beqz $a3, .Loptimized_memcpy_9" "\n"
1796 "\t" " nop" "\n"
1797 "\t" " srl $a3, $a2, 2" "\n"
1798 "\t" " addiu $at, $zero, 0xC" "\n"
1799 "\t" " div $zero, $a3, $at" "\n"
1800 "\t" " mflo $a3" "\n"
1801 "\t" " mfhi $v1" "\n"
1802 "\t" " beqz $v1, .Loptimized_memcpy_8" "\n"
1803 "\t" " nop" "\n"
1804 "\t" ".Loptimized_memcpy_7:" "\n"
1805 "\t" " lw $v0, 0x0($a1)" "\n"
1806 "\t" " addiu $v1, $v1, -0x1" "\n"
1807 "\t" " swl $v0, 0x3($a0)" "\n"
1808 "\t" " swr $v0, 0x0($a0)" "\n"
1809 "\t" " addiu $a1, $a1, 0x4" "\n"
1810 "\t" " bnez $v1, .Loptimized_memcpy_7" "\n"
1811 "\t" " addiu $a0, $a0, 0x4" "\n"
1812 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
1813 "\t" " nop" "\n"
1814 "\t" ".Loptimized_memcpy_8:" "\n"
1815 "\t" " lw $v0, 0x0($a1)" "\n"
1816 "\t" " lw $v1, 0x4($a1)" "\n"
1817 "\t" " lw $t0, 0x8($a1)" "\n"
1818 "\t" " lw $t1, 0xC($a1)" "\n"
1819 "\t" " lw $t2, 0x10($a1)" "\n"
1820 "\t" " lw $t3, 0x14($a1)" "\n"
1821 "\t" " lw $t4, 0x18($a1)" "\n"
1822 "\t" " lw $t5, 0x1C($a1)" "\n"
1823 "\t" " lw $t6, 0x20($a1)" "\n"
1824 "\t" " lw $t7, 0x24($a1)" "\n"
1825 "\t" " lw $t8, 0x28($a1)" "\n"
1826 "\t" " lw $t9, 0x2C($a1)" "\n"
1827 "\t" " addiu $a3, $a3, -0x1" "\n"
1828 "\t" " swl $v0, 0x3($a0)" "\n"
1829 "\t" " swr $v0, 0x0($a0)" "\n"
1830 "\t" " swl $v1, 0x7($a0)" "\n"
1831 "\t" " swr $v1, 0x4($a0)" "\n"
1832 "\t" " swl $t0, 0xB($a0)" "\n"
1833 "\t" " swr $t0, 0x8($a0)" "\n"
1834 "\t" " swl $t1, 0xF($a0)" "\n"
1835 "\t" " swr $t1, 0xC($a0)" "\n"
1836 "\t" " swl $t2, 0x13($a0)" "\n"
1837 "\t" " swr $t2, 0x10($a0)" "\n"
1838 "\t" " swl $t3, 0x17($a0)" "\n"
1839 "\t" " swr $t3, 0x14($a0)" "\n"
1840 "\t" " swl $t4, 0x1B($a0)" "\n"
1841 "\t" " swr $t4, 0x18($a0)" "\n"
1842 "\t" " swl $t5, 0x1F($a0)" "\n"
1843 "\t" " swr $t5, 0x1C($a0)" "\n"
1844 "\t" " swl $t6, 0x23($a0)" "\n"
1845 "\t" " swr $t6, 0x20($a0)" "\n"
1846 "\t" " swl $t7, 0x27($a0)" "\n"
1847 "\t" " swr $t7, 0x24($a0)" "\n"
1848 "\t" " swl $t8, 0x2B($a0)" "\n"
1849 "\t" " swr $t8, 0x28($a0)" "\n"
1850 "\t" " swl $t9, 0x2F($a0)" "\n"
1851 "\t" " swr $t9, 0x2C($a0)" "\n"
1852 "\t" " addiu $a1, $a1, 0x30" "\n"
1853 "\t" " bnez $a3, .Loptimized_memcpy_8" "\n"
1854 "\t" " addiu $a0, $a0, 0x30" "\n"
1855 "\t" " j .Loptimized_memcpy_12" "\n"
1856 "\t" " nop" "\n"
1857 "\t" ".Loptimized_memcpy_9:" "\n"
1858 "\t" " srl $a3, $a2, 2" "\n"
1859 "\t" " addiu $at, $zero, 0xC" "\n"
1860 "\t" " div $zero, $a3, $at" "\n"
1861 "\t" " mflo $a3" "\n"
1862 "\t" " mfhi $v1" "\n"
1863 "\t" " beqz $v1, .Loptimized_memcpy_11" "\n"
1864 "\t" " nop" "\n"
1865 "\t" ".Loptimized_memcpy_10:" "\n"
1866 "\t" " lwl $v0, 0x3($a1)" "\n"
1867 "\t" " lwr $v0, 0x0($a1)" "\n"
1868 "\t" " addiu $v1, $v1, -0x1" "\n"
1869 "\t" " sw $v0, 0x0($a0)" "\n"
1870 "\t" " addiu $a1, $a1, 0x4" "\n"
1871 "\t" " bnez $v1, .Loptimized_memcpy_10" "\n"
1872 "\t" " addiu $a0, $a0, 0x4" "\n"
1873 "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
1874 "\t" " nop" "\n"
1875 "\t" ".Loptimized_memcpy_11:" "\n"
1876 "\t" " lwl $v0, 0x3($a1)" "\n"
1877 "\t" " lwr $v0, 0x0($a1)" "\n"
1878 "\t" " lwl $v1, 0x7($a1)" "\n"
1879 "\t" " lwr $v1, 0x4($a1)" "\n"
1880 "\t" " lwl $t0, 0xB($a1)" "\n"
1881 "\t" " lwr $t0, 0x8($a1)" "\n"
1882 "\t" " lwl $t1, 0xF($a1)" "\n"
1883 "\t" " lwr $t1, 0xC($a1)" "\n"
1884 "\t" " lwl $t2, 0x13($a1)" "\n"
1885 "\t" " lwr $t2, 0x10($a1)" "\n"
1886 "\t" " lwl $t3, 0x17($a1)" "\n"
1887 "\t" " lwr $t3, 0x14($a1)" "\n"
1888 "\t" " lwl $t4, 0x1B($a1)" "\n"
1889 "\t" " lwr $t4, 0x18($a1)" "\n"
1890 "\t" " lwl $t5, 0x1F($a1)" "\n"
1891 "\t" " lwr $t5, 0x1C($a1)" "\n"
1892 "\t" " lwl $t6, 0x23($a1)" "\n"
1893 "\t" " lwr $t6, 0x20($a1)" "\n"
1894 "\t" " lwl $t7, 0x27($a1)" "\n"
1895 "\t" " lwr $t7, 0x24($a1)" "\n"
1896 "\t" " lwl $t8, 0x2B($a1)" "\n"
1897 "\t" " lwr $t8, 0x28($a1)" "\n"
1898 "\t" " lwl $t9, 0x2F($a1)" "\n"
1899 "\t" " lwr $t9, 0x2C($a1)" "\n"
1900 "\t" " addiu $a3, $a3, -0x1" "\n"
1901 "\t" " sw $v0, 0x0($a0)" "\n"
1902 "\t" " sw $v1, 0x4($a0)" "\n"
1903 "\t" " sw $t0, 0x8($a0)" "\n"
1904 "\t" " sw $t1, 0xC($a0)" "\n"
1905 "\t" " sw $t2, 0x10($a0)" "\n"
1906 "\t" " sw $t3, 0x14($a0)" "\n"
1907 "\t" " sw $t4, 0x18($a0)" "\n"
1908 "\t" " sw $t5, 0x1C($a0)" "\n"
1909 "\t" " sw $t6, 0x20($a0)" "\n"
1910 "\t" " sw $t7, 0x24($a0)" "\n"
1911 "\t" " sw $t8, 0x28($a0)" "\n"
1912 "\t" " sw $t9, 0x2C($a0)" "\n"
1913 "\t" " addiu $a1, $a1, 0x30" "\n"
1914 "\t" " bnez $a3, .Loptimized_memcpy_11" "\n"
1915 "\t" " addiu $a0, $a0, 0x30" "\n"
1916 "\t" ".Loptimized_memcpy_12:" "\n"
1917 "\t" " andi $v1, $a2, 0x3" "\n"
1918 "\t" " beqz $v1, .Loptimized_memcpy_14" "\n"
1919 "\t" " nop" "\n"
1920 "\t" ".Loptimized_memcpy_13:" "\n"
1921 "\t" " lb $v0, 0x0($a1)" "\n"
1922 "\t" " addiu $v1, $v1, -0x1" "\n"
1923 "\t" " sb $v0, 0x0($a0)" "\n"
1924 "\t" " addiu $a1, $a1, 0x1" "\n"
1925 "\t" " bnez $v1, .Loptimized_memcpy_13" "\n"
1926 "\t" " addiu $a0, $a0, 0x1" "\n"
1927 "\t" ".Loptimized_memcpy_14:" "\n"
1928 "\t" " addu $v0, $a2, $zero" "\n"
1929 "\t" " jr $ra" "\n"
1930 "\t" " nop" "\n"
1931 "\t" ".set pop" "\n"
1932);
1933// clang-format on
#define EIO
Definition errno.h:29
int CpuResumeIntr(int state)
Definition intrman.c:227
int QueryIntrContext(void)
int CpuSuspendIntr(int *state)
Definition intrman.c:205
#define IOP_DT_FSEXT
Definition iomanX.h:66
int sceCdBreak(void)
Definition cdi.c:25
int sceCdStStop(void)
Definition cdi.c:214
int sceCdGetDiskType(void)
Definition cdi.c:35
int sceCdSync(int mode)
Definition cdi.c:109
@ SCECdSpinMax
@ SCECdPSCDDA
@ SCECdPSCD
@ SCECdPS2DVD
@ SCECdCDDA
@ SCECdPS2CDDA
@ SCECdPS2CD
@ SCECdErREAD
@ SCECdErABRT
@ SCECdErREADCF
int sceCdRE(unsigned int lsn, unsigned int sectors, void *buf, sceCdRMode *mode)
Definition cdvdman.c:6862
u16 newflags
Definition loadcore.h:36