/
cellSpurs.cpp
5441 lines (4407 loc) · 150 KB
/
cellSpurs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/IdManager.h"
#include "Emu/Memory/vm_reservation.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/SPUThread.h"
#include "Emu/Cell/lv2/sys_lwmutex.h"
#include "Emu/Cell/lv2/sys_lwcond.h"
#include "Emu/Cell/lv2/sys_spu.h"
#include "Emu/Cell/lv2/sys_ppu_thread.h"
#include "Emu/Cell/lv2/sys_memory.h"
#include "Emu/Cell/lv2/sys_process.h"
#include "Emu/Cell/lv2/sys_semaphore.h"
#include "Emu/Cell/lv2/sys_event.h"
#include "sysPrxForUser.h"
#include "cellSpurs.h"
#include "util/asm.hpp"
#include "util/v128.hpp"
#include "util/simd.hpp"
LOG_CHANNEL(cellSpurs);
template <>
void fmt_class_string<CellSpursCoreError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_SPURS_CORE_ERROR_AGAIN);
STR_CASE(CELL_SPURS_CORE_ERROR_INVAL);
STR_CASE(CELL_SPURS_CORE_ERROR_NOMEM);
STR_CASE(CELL_SPURS_CORE_ERROR_SRCH);
STR_CASE(CELL_SPURS_CORE_ERROR_PERM);
STR_CASE(CELL_SPURS_CORE_ERROR_BUSY);
STR_CASE(CELL_SPURS_CORE_ERROR_STAT);
STR_CASE(CELL_SPURS_CORE_ERROR_ALIGN);
STR_CASE(CELL_SPURS_CORE_ERROR_NULL_POINTER);
}
return unknown;
});
}
template <>
void fmt_class_string<CellSpursPolicyModuleError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_SPURS_POLICY_MODULE_ERROR_AGAIN);
STR_CASE(CELL_SPURS_POLICY_MODULE_ERROR_INVAL);
STR_CASE(CELL_SPURS_POLICY_MODULE_ERROR_NOSYS);
STR_CASE(CELL_SPURS_POLICY_MODULE_ERROR_NOMEM);
STR_CASE(CELL_SPURS_POLICY_MODULE_ERROR_SRCH);
STR_CASE(CELL_SPURS_POLICY_MODULE_ERROR_NOENT);
STR_CASE(CELL_SPURS_POLICY_MODULE_ERROR_NOEXEC);
STR_CASE(CELL_SPURS_POLICY_MODULE_ERROR_DEADLK);
STR_CASE(CELL_SPURS_POLICY_MODULE_ERROR_PERM);
STR_CASE(CELL_SPURS_POLICY_MODULE_ERROR_BUSY);
STR_CASE(CELL_SPURS_POLICY_MODULE_ERROR_ABORT);
STR_CASE(CELL_SPURS_POLICY_MODULE_ERROR_FAULT);
STR_CASE(CELL_SPURS_POLICY_MODULE_ERROR_CHILD);
STR_CASE(CELL_SPURS_POLICY_MODULE_ERROR_STAT);
STR_CASE(CELL_SPURS_POLICY_MODULE_ERROR_ALIGN);
STR_CASE(CELL_SPURS_POLICY_MODULE_ERROR_NULL_POINTER);
}
return unknown;
});
}
template <>
void fmt_class_string<CellSpursTaskError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_SPURS_TASK_ERROR_AGAIN);
STR_CASE(CELL_SPURS_TASK_ERROR_INVAL);
STR_CASE(CELL_SPURS_TASK_ERROR_NOSYS);
STR_CASE(CELL_SPURS_TASK_ERROR_NOMEM);
STR_CASE(CELL_SPURS_TASK_ERROR_SRCH);
STR_CASE(CELL_SPURS_TASK_ERROR_NOEXEC);
STR_CASE(CELL_SPURS_TASK_ERROR_PERM);
STR_CASE(CELL_SPURS_TASK_ERROR_BUSY);
STR_CASE(CELL_SPURS_TASK_ERROR_FAULT);
STR_CASE(CELL_SPURS_TASK_ERROR_ALIGN);
STR_CASE(CELL_SPURS_TASK_ERROR_STAT);
STR_CASE(CELL_SPURS_TASK_ERROR_NULL_POINTER);
STR_CASE(CELL_SPURS_TASK_ERROR_FATAL);
STR_CASE(CELL_SPURS_TASK_ERROR_SHUTDOWN);
}
return unknown;
});
}
template <>
void fmt_class_string<CellSpursJobError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_SPURS_JOB_ERROR_AGAIN);
STR_CASE(CELL_SPURS_JOB_ERROR_INVAL);
STR_CASE(CELL_SPURS_JOB_ERROR_NOSYS);
STR_CASE(CELL_SPURS_JOB_ERROR_NOMEM);
STR_CASE(CELL_SPURS_JOB_ERROR_SRCH);
STR_CASE(CELL_SPURS_JOB_ERROR_NOENT);
STR_CASE(CELL_SPURS_JOB_ERROR_NOEXEC);
STR_CASE(CELL_SPURS_JOB_ERROR_DEADLK);
STR_CASE(CELL_SPURS_JOB_ERROR_PERM);
STR_CASE(CELL_SPURS_JOB_ERROR_BUSY);
STR_CASE(CELL_SPURS_JOB_ERROR_JOB_DESCRIPTOR);
STR_CASE(CELL_SPURS_JOB_ERROR_JOB_DESCRIPTOR_SIZE);
STR_CASE(CELL_SPURS_JOB_ERROR_FAULT);
STR_CASE(CELL_SPURS_JOB_ERROR_CHILD);
STR_CASE(CELL_SPURS_JOB_ERROR_STAT);
STR_CASE(CELL_SPURS_JOB_ERROR_ALIGN);
STR_CASE(CELL_SPURS_JOB_ERROR_NULL_POINTER);
STR_CASE(CELL_SPURS_JOB_ERROR_MEMORY_CORRUPTED);
STR_CASE(CELL_SPURS_JOB_ERROR_MEMORY_SIZE);
STR_CASE(CELL_SPURS_JOB_ERROR_UNKNOWN_COMMAND);
STR_CASE(CELL_SPURS_JOB_ERROR_JOBLIST_ALIGNMENT);
STR_CASE(CELL_SPURS_JOB_ERROR_JOB_ALIGNMENT);
STR_CASE(CELL_SPURS_JOB_ERROR_CALL_OVERFLOW);
STR_CASE(CELL_SPURS_JOB_ERROR_ABORT);
STR_CASE(CELL_SPURS_JOB_ERROR_DMALIST_ELEMENT);
STR_CASE(CELL_SPURS_JOB_ERROR_NUM_CACHE);
STR_CASE(CELL_SPURS_JOB_ERROR_INVALID_BINARY);
}
return unknown;
});
}
template <>
void fmt_class_string<SpursWorkloadState>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
case SPURS_WKL_STATE_NON_EXISTENT: return "Non-existent";
case SPURS_WKL_STATE_PREPARING: return "Preparing";
case SPURS_WKL_STATE_RUNNABLE: return "Runnable";
case SPURS_WKL_STATE_SHUTTING_DOWN: return "In-shutdown";
case SPURS_WKL_STATE_REMOVABLE: return "Removable";
case SPURS_WKL_STATE_INVALID: break;
}
return unknown;
});
}
error_code sys_spu_image_close(ppu_thread&, vm::ptr<sys_spu_image> img);
// Temporarily
#ifndef _MSC_VER
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
//----------------------------------------------------------------------------
// Function prototypes
//----------------------------------------------------------------------------
bool spursKernelEntry(spu_thread& spu);
// SPURS Internals
namespace _spurs
{
// Get the version of SDK used by this process
s32 get_sdk_version();
// Check whether libprof is loaded
bool is_libprof_loaded();
// Create an LV2 event queue and attach it to the SPURS instance
s32 create_lv2_eq(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, vm::ptr<u32> queueId, vm::ptr<u8> port, s32 size, const sys_event_queue_attribute_t& name);
// Attach an LV2 event queue to the SPURS instance
s32 attach_lv2_eq(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 queue, vm::ptr<u8> port, s32 isDynamic, bool spursCreated);
// Detach an LV2 event queue from the SPURS instance
s32 detach_lv2_eq(vm::ptr<CellSpurs> spurs, u8 spuPort, bool spursCreated);
// Wait until a workload in the SPURS instance becomes ready
void handler_wait_ready(ppu_thread& ppu, vm::ptr<CellSpurs> spurs);
// Entry point of the SPURS handler thread. This thread is responsible for starting the SPURS SPU thread group.
void handler_entry(ppu_thread& ppu, vm::ptr<CellSpurs> spurs);
// Create the SPURS handler thread
s32 create_handler(vm::ptr<CellSpurs> spurs, u32 ppuPriority);
// Invoke event handlers
s32 invoke_event_handlers(ppu_thread& ppu, vm::ptr<CellSpurs::EventPortMux> eventPortMux);
// Invoke workload shutdown completion callbacks
s32 wakeup_shutdown_completion_waiter(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 wid);
// Entry point of the SPURS event helper thread
void event_helper_entry(ppu_thread& ppu, vm::ptr<CellSpurs> spurs);
// Create the SPURS event helper thread
s32 create_event_helper(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 ppuPriority);
// Initialise the event port multiplexor structure
void init_event_port_mux(vm::ptr<CellSpurs::EventPortMux> eventPortMux, u8 spuPort, u32 eventPort, u32 unknown);
// Enable the system workload
s32 add_default_syswkl(vm::ptr<CellSpurs> spurs, vm::cptr<u8> swlPriority, u32 swlMaxSpu, u32 swlIsPreem);
// Destroy the SPURS SPU threads and thread group
s32 finalize_spu(ppu_thread&, vm::ptr<CellSpurs> spurs);
// Stop the event helper thread
s32 stop_event_helper(ppu_thread& ppu, vm::ptr<CellSpurs> spurs);
// Signal to the SPURS handler thread
s32 signal_to_handler_thread(ppu_thread& ppu, vm::ptr<CellSpurs> spurs);
// Join the SPURS handler thread
s32 join_handler_thread(ppu_thread& ppu, vm::ptr<CellSpurs> spurs);
// Initialise SPURS
s32 initialize(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 revision, u32 sdkVersion, s32 nSpus, s32 spuPriority, s32 ppuPriority, u32 flags, vm::cptr<char> prefix, u32 prefixSize, u32 container, vm::cptr<u8> swlPriority, u32 swlMaxSpu, u32 swlIsPreem);
}
//
// SPURS Core Functions
//
//s32 cellSpursInitialize(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, s32 nSpus, s32 spuPriority, s32 ppuPriority, b8 exitIfNoWork);
//s32 cellSpursInitializeWithAttribute(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, vm::cptr<CellSpursAttribute> attr);
//s32 cellSpursInitializeWithAttribute2(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, vm::cptr<CellSpursAttribute> attr);
//s32 _cellSpursAttributeInitialize(vm::ptr<CellSpursAttribute> attr, u32 revision, u32 sdkVersion, u32 nSpus, s32 spuPriority, s32 ppuPriority, b8 exitIfNoWork);
//s32 cellSpursAttributeSetMemoryContainerForSpuThread(vm::ptr<CellSpursAttribute> attr, u32 container);
//s32 cellSpursAttributeSetNamePrefix(vm::ptr<CellSpursAttribute> attr, vm::cptr<char> prefix, u32 size);
//s32 cellSpursAttributeEnableSpuPrintfIfAvailable(vm::ptr<CellSpursAttribute> attr);
//s32 cellSpursAttributeSetSpuThreadGroupType(vm::ptr<CellSpursAttribute> attr, s32 type);
//s32 cellSpursAttributeEnableSystemWorkload(vm::ptr<CellSpursAttribute> attr, vm::cptr<u8[8]> priority, u32 maxSpu, vm::cptr<b8[8]> isPreemptible);
//s32 cellSpursFinalize(vm::ptr<CellSpurs> spurs);
//s32 cellSpursGetSpuThreadGroupId(vm::ptr<CellSpurs> spurs, vm::ptr<u32> group);
//s32 cellSpursGetNumSpuThread(vm::ptr<CellSpurs> spurs, vm::ptr<u32> nThreads);
//s32 cellSpursGetSpuThreadId(vm::ptr<CellSpurs> spurs, vm::ptr<u32> thread, vm::ptr<u32> nThreads);
//s32 cellSpursSetMaxContention(vm::ptr<CellSpurs> spurs, u32 wid, u32 maxContention);
//s32 cellSpursSetPriorities(vm::ptr<CellSpurs> spurs, u32 wid, vm::cptr<u8> priorities);
//s32 cellSpursSetPreemptionVictimHints(vm::ptr<CellSpurs> spurs, vm::cptr<b8> isPreemptible);
//s32 cellSpursAttachLv2EventQueue(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 queue, vm::ptr<u8> port, s32 isDynamic);
//s32 cellSpursDetachLv2EventQueue(vm::ptr<CellSpurs> spurs, u8 port);
// Enable the SPU exception event handler
s32 cellSpursEnableExceptionEventHandler(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, b8 flag);
//s32 cellSpursSetGlobalExceptionEventHandler(vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursGlobalExceptionEventHandler> eaHandler, vm::ptr<void> arg);
//s32 cellSpursUnsetGlobalExceptionEventHandler(vm::ptr<CellSpurs> spurs);
//s32 cellSpursGetInfo(vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursInfo> info);
//
// SPURS SPU GUID functions
//
//s32 cellSpursGetSpuGuid();
//
// SPURS trace functions
//
namespace _spurs
{
// Signal SPUs to update trace status
void trace_status_update(ppu_thread& ppu, vm::ptr<CellSpurs> spurs);
// Initialize SPURS trace
s32 trace_initialize(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursTraceInfo> buffer, u32 size, u32 mode, u32 updateStatus);
// Start SPURS trace
s32 trace_start(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 updateStatus);
// Stop SPURS trace
s32 trace_stop(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 updateStatus);
}
//s32 cellSpursTraceInitialize(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursTraceInfo> buffer, u32 size, u32 mode);
//s32 cellSpursTraceFinalize(ppu_thread& ppu, vm::ptr<CellSpurs> spurs);
//s32 cellSpursTraceStart(ppu_thread& ppu, vm::ptr<CellSpurs> spurs);
//s32 cellSpursTraceStop(ppu_thread& ppu, vm::ptr<CellSpurs> spurs);
//
// SPURS policy module functions
//
namespace _spurs
{
// Add workload
s32 add_workload(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, vm::ptr<u32> wid, vm::cptr<void> pm, u32 size, u64 data, const u8(&priorityTable)[8], u32 minContention, u32 maxContention, vm::cptr<char> nameClass, vm::cptr<char> nameInstance, vm::ptr<CellSpursShutdownCompletionEventHook> hook, vm::ptr<void> hookArg);
}
//s32 _cellSpursWorkloadAttributeInitialize(vm::ptr<CellSpursWorkloadAttribute> attr, u32 revision, u32 sdkVersion, vm::cptr<void> pm, u32 size, u64 data, vm::cptr<u8[8]> priority, u32 minCnt, u32 maxCnt);
//s32 cellSpursWorkloadAttributeSetName(vm::ptr<CellSpursWorkloadAttribute> attr, vm::cptr<char> nameClass, vm::cptr<char> nameInstance);
//s32 cellSpursWorkloadAttributeSetShutdownCompletionEventHook(vm::ptr<CellSpursWorkloadAttribute> attr, vm::ptr<CellSpursShutdownCompletionEventHook> hook, vm::ptr<void> arg);
//s32 cellSpursAddWorkload(vm::ptr<CellSpurs> spurs, vm::ptr<u32> wid, vm::cptr<void> pm, u32 size, u64 data, vm::cptr<u8[8]> priority, u32 minCnt, u32 maxCnt);
//s32 cellSpursAddWorkloadWithAttribute(vm::ptr<CellSpurs> spurs, vm::ptr<u32> wid, vm::cptr<CellSpursWorkloadAttribute> attr);
//s32 cellSpursShutdownWorkload();
//s32 cellSpursWaitForWorkloadShutdown();
//s32 cellSpursRemoveWorkload();
// Activate the SPURS kernel
s32 cellSpursWakeUp(ppu_thread& ppu, vm::ptr<CellSpurs> spurs);
s32 cellSpursSendWorkloadSignal(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 wid);
//s32 cellSpursGetWorkloadFlag(vm::ptr<CellSpurs> spurs, vm::pptr<CellSpursWorkloadFlag> flag);
s32 cellSpursReadyCountStore(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 wid, u32 value);
s32 cellSpursReadyCountSwap(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 wid, vm::ptr<u32> old, u32 swap);
s32 cellSpursReadyCountCompareAndSwap(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 wid, vm::ptr<u32> old, u32 compare, u32 swap);
s32 cellSpursReadyCountAdd(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 wid, vm::ptr<u32> old, s32 value);
//s32 cellSpursGetWorkloadData(vm::ptr<CellSpurs> spurs, vm::ptr<u64> data, u32 wid);
//s32 cellSpursGetWorkloadInfo();
//s32 cellSpursSetExceptionEventHandler();
//s32 cellSpursUnsetExceptionEventHandler();
s32 _cellSpursWorkloadFlagReceiver(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 wid, u32 is_set);
//s32 _cellSpursWorkloadFlagReceiver2();
//s32 cellSpursRequestIdleSpu();
//
// SPURS taskset functions
//
namespace _spurs
{
// Create taskset
s32 create_taskset(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursTaskset> taskset, u64 args, vm::cptr<u8[8]> priority, u32 max_contention, vm::cptr<char> name, u32 size, s32 enable_clear_ls);
}
//s32 cellSpursCreateTasksetWithAttribute(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursTaskset> taskset, vm::ptr<CellSpursTasksetAttribute> attr);
//s32 cellSpursCreateTaskset(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursTaskset> taskset, u64 args, vm::cptr<u8[8]> priority, u32 maxContention);
//s32 cellSpursJoinTaskset(vm::ptr<CellSpursTaskset> taskset);
//s32 cellSpursGetTasksetId(vm::ptr<CellSpursTaskset> taskset, vm::ptr<u32> wid);
//s32 cellSpursShutdownTaskset(vm::ptr<CellSpursTaskset> taskset);
//s32 cellSpursTasksetAttributeSetName(vm::ptr<CellSpursTasksetAttribute> attr, vm::cptr<char> name);
//s32 cellSpursTasksetAttributeSetTasksetSize(vm::ptr<CellSpursTasksetAttribute> attr, u32 size);
//s32 cellSpursTasksetAttributeEnableClearLS(vm::ptr<CellSpursTasksetAttribute> attr, s32 enable);
//s32 _cellSpursTasksetAttribute2Initialize(vm::ptr<CellSpursTasksetAttribute2> attribute, u32 revision);
//s32 cellSpursCreateTaskset2(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursTaskset> taskset, vm::ptr<CellSpursTasksetAttribute2> attr);
//s32 cellSpursDestroyTaskset2();
//s32 cellSpursTasksetSetExceptionEventHandler(vm::ptr<CellSpursTaskset> taskset, vm::ptr<CellSpursTasksetExceptionEventHandler> handler, vm::ptr<u64> arg);
//s32 cellSpursTasksetUnsetExceptionEventHandler(vm::ptr<CellSpursTaskset> taskset);
// Get taskset instance from the workload ID
s32 cellSpursLookUpTasksetAddress(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, vm::pptr<CellSpursTaskset> taskset, u32 id);
//s32 cellSpursTasksetGetSpursAddress(vm::cptr<CellSpursTaskset> taskset, vm::ptr<u32> spurs);
//s32 cellSpursGetTasksetInfo();
//s32 _cellSpursTasksetAttributeInitialize(vm::ptr<CellSpursTasksetAttribute> attribute, u32 revision, u32 sdk_version, u64 args, vm::cptr<u8> priority, u32 max_contention);
//
// SPURS task functions
//
namespace _spurs
{
// Create task
s32 create_task(vm::ptr<CellSpursTaskset> taskset, vm::ptr<u32> task_id, vm::cptr<void> elf, vm::cptr<void> context, u32 size, vm::ptr<CellSpursTaskLsPattern> ls_pattern, vm::ptr<CellSpursTaskArgument> arg);
// Start task
s32 task_start(ppu_thread& ppu, vm::ptr<CellSpursTaskset> taskset, u32 taskId);
}
//s32 cellSpursCreateTask(ppu_thread& ppu, vm::ptr<CellSpursTaskset> taskset, vm::ptr<u32> taskId, vm::cptr<void> elf, vm::cptr<void> context, u32 size, vm::ptr<CellSpursTaskLsPattern> lsPattern, vm::ptr<CellSpursTaskArgument> argument);
// Sends a signal to the task
s32 _cellSpursSendSignal(ppu_thread& ppu, vm::ptr<CellSpursTaskset> taskset, u32 taskId);
//s32 cellSpursCreateTaskWithAttribute();
//s32 cellSpursTaskExitCodeGet();
//s32 cellSpursTaskExitCodeInitialize();
//s32 cellSpursTaskExitCodeTryGet();
//s32 cellSpursTaskGetLoadableSegmentPattern();
//s32 cellSpursTaskGetReadOnlyAreaPattern();
//s32 cellSpursTaskGenerateLsPattern();
//s32 _cellSpursTaskAttributeInitialize();
//s32 cellSpursTaskAttributeSetExitCodeContainer();
//s32 _cellSpursTaskAttribute2Initialize(vm::ptr<CellSpursTaskAttribute2> attribute, u32 revision);
//s32 cellSpursTaskGetContextSaveAreaSize();
//s32 cellSpursCreateTask2();
//s32 cellSpursJoinTask2();
//s32 cellSpursTryJoinTask2();
//s32 cellSpursCreateTask2WithBinInfo();
//
// SPURS event flag functions
//
namespace _spurs
{
// Wait for SPURS event flag
s32 event_flag_wait(ppu_thread& ppu, vm::ptr<CellSpursEventFlag> eventFlag, vm::ptr<u16> mask, u32 mode, u32 block);
}
//s32 _cellSpursEventFlagInitialize(vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursTaskset> taskset, vm::ptr<CellSpursEventFlag> eventFlag, u32 flagClearMode, u32 flagDirection);
//s32 cellSpursEventFlagClear(vm::ptr<CellSpursEventFlag> eventFlag, u16 bits);
//s32 cellSpursEventFlagSet(ppu_thread& ppu, vm::ptr<CellSpursEventFlag> eventFlag, u16 bits);
//s32 cellSpursEventFlagWait(ppu_thread& ppu, vm::ptr<CellSpursEventFlag> eventFlag, vm::ptr<u16> mask, u32 mode);
//s32 cellSpursEventFlagTryWait(ppu_thread& ppu, vm::ptr<CellSpursEventFlag> eventFlag, vm::ptr<u16> mask, u32 mode);
//s32 cellSpursEventFlagAttachLv2EventQueue(ppu_thread& ppu, vm::ptr<CellSpursEventFlag> eventFlag);
//s32 cellSpursEventFlagDetachLv2EventQueue(ppu_thread& ppu, vm::ptr<CellSpursEventFlag> eventFlag);
//s32 cellSpursEventFlagGetDirection(vm::ptr<CellSpursEventFlag> eventFlag, vm::ptr<u32> direction);
//s32 cellSpursEventFlagGetClearMode(vm::ptr<CellSpursEventFlag> eventFlag, vm::ptr<u32> clear_mode);
//s32 cellSpursEventFlagGetTasksetAddress(vm::ptr<CellSpursEventFlag> eventFlag, vm::pptr<CellSpursTaskset> taskset);
//
// SPURS lock free queue functions
//
//s32 _cellSpursLFQueueInitialize(vm::ptr<void> pTasksetOrSpurs, vm::ptr<CellSpursLFQueue> pQueue, vm::cptr<void> buffer, u32 size, u32 depth, u32 direction);
//s32 _cellSpursLFQueuePushBody();
//s32 cellSpursLFQueueAttachLv2EventQueue(vm::ptr<CellSyncLFQueue> queue);
//s32 cellSpursLFQueueDetachLv2EventQueue(vm::ptr<CellSyncLFQueue> queue);
//s32 _cellSpursLFQueuePopBody();
//s32 cellSpursLFQueueGetTasksetAddress();
//
// SPURS queue functions
//
//s32 _cellSpursQueueInitialize();
//s32 cellSpursQueuePopBody();
//s32 cellSpursQueuePushBody();
//s32 cellSpursQueueAttachLv2EventQueue();
//s32 cellSpursQueueDetachLv2EventQueue();
//s32 cellSpursQueueGetTasksetAddress();
//s32 cellSpursQueueClear();
//s32 cellSpursQueueDepth();
//s32 cellSpursQueueGetEntrySize();
//s32 cellSpursQueueSize();
//s32 cellSpursQueueGetDirection();
//
// SPURS barrier functions
//
//s32 cellSpursBarrierInitialize();
//s32 cellSpursBarrierGetTasksetAddress();
//
// SPURS semaphore functions
//
//s32 _cellSpursSemaphoreInitialize();
//s32 cellSpursSemaphoreGetTasksetAddress();
//
// SPURS job chain functions
//
namespace _spurs
{
s32 check_job_chain_attribute(u32 sdkVer, vm::cptr<u64> jcEntry, u16 sizeJobDescr, u16 maxGrabbedJob
, u64 priorities, u32 maxContention, u8 autoSpuCount, u32 tag1, u32 tag2
, u8 isFixedMemAlloc, u32 maxSizeJob, u32 initSpuCount);
s32 create_job_chain(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursJobChain> jobChain, vm::cptr<u64> jobChainEntry, u16 sizeJob
, u16 maxGrabbedJob, vm::cptr<u8[8]> prio, u32 maxContention, b8 autoReadyCount
, u32 tag1, u32 tag2, u32 HaltOnError, vm::cptr<char> name, u32 param_13, u32 param_14);
}
//s32 cellSpursCreateJobChainWithAttribute();
//s32 cellSpursCreateJobChain();
//s32 cellSpursJoinJobChain();
s32 cellSpursKickJobChain(ppu_thread& ppu, vm::ptr<CellSpursJobChain> jobChain, u8 numReadyCount);
//s32 _cellSpursJobChainAttributeInitialize();
//s32 cellSpursGetJobChainId();
//s32 cellSpursJobChainSetExceptionEventHandler();
//s32 cellSpursJobChainUnsetExceptionEventHandler();
//s32 cellSpursGetJobChainInfo();
//s32 cellSpursJobChainGetSpursAddress();
//s32 cellSpursJobGuardInitialize();
//s32 cellSpursJobChainAttributeSetName();
//s32 cellSpursShutdownJobChain();
//s32 cellSpursJobChainAttributeSetHaltOnError();
//s32 cellSpursJobChainAttributeSetJobTypeMemoryCheck();
//s32 cellSpursJobGuardNotify();
//s32 cellSpursJobGuardReset();
s32 cellSpursRunJobChain(ppu_thread& ppu, vm::ptr<CellSpursJobChain> jobChain);
//s32 cellSpursJobChainGetError();
//s32 cellSpursGetJobPipelineInfo();
//s32 cellSpursJobSetMaxGrab();
//s32 cellSpursJobHeaderSetJobbin2Param();
//s32 cellSpursAddUrgentCommand();
//s32 cellSpursAddUrgentCall();
//----------------------------------------------------------------------------
// SPURS utility functions
//----------------------------------------------------------------------------
s32 _spurs::get_sdk_version()
{
const s32 version = static_cast<s32>(g_ps3_process_info.sdk_ver);
return version == -1 ? 0x485000 : version;
}
bool _spurs::is_libprof_loaded()
{
return false;
}
//----------------------------------------------------------------------------
// SPURS core functions
//----------------------------------------------------------------------------
s32 _spurs::create_lv2_eq(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, vm::ptr<u32> queueId, vm::ptr<u8> port, s32 size, const sys_event_queue_attribute_t& attr)
{
if (s32 rc = sys_event_queue_create(ppu, queueId, vm::make_var(attr), SYS_EVENT_QUEUE_LOCAL, size))
{
static_cast<void>(ppu.test_stopped());
return rc;
}
if (_spurs::attach_lv2_eq(ppu, spurs, *queueId, port, 1, true))
{
sys_event_queue_destroy(ppu, *queueId, SYS_EVENT_QUEUE_DESTROY_FORCE);
static_cast<void>(ppu.test_stopped());
}
return CELL_OK;
}
s32 _spurs::attach_lv2_eq(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 queue, vm::ptr<u8> port, s32 isDynamic, bool spursCreated)
{
if (!spurs || !port)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
if (spurs->exception)
{
return CELL_SPURS_CORE_ERROR_STAT;
}
u8 _port = 0x3f;
u64 portMask = 0;
if (isDynamic == 0)
{
_port = *port;
if (_port > 0x3f)
{
return CELL_SPURS_CORE_ERROR_INVAL;
}
if (_spurs::get_sdk_version() >= 0x180000 && _port > 0xf)
{
return CELL_SPURS_CORE_ERROR_PERM;
}
}
for (u32 i = isDynamic ? 0x10 : _port; i <= _port; i++)
{
portMask |= 1ull << (i);
}
if (s32 res = sys_spu_thread_group_connect_event_all_threads(ppu, spurs->spuTG, queue, portMask, port))
{
if (res + 0u == CELL_EISCONN)
{
return CELL_SPURS_CORE_ERROR_BUSY;
}
return res;
}
if (!spursCreated)
{
spurs->spuPortBits |= 1ull << *port;
}
return CELL_OK;
}
s32 _spurs::detach_lv2_eq(vm::ptr<CellSpurs> spurs, u8 spuPort, bool spursCreated)
{
if (!spurs)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
if (!spursCreated && spurs->exception)
{
return CELL_SPURS_CORE_ERROR_STAT;
}
if (spuPort > 0x3F)
{
return CELL_SPURS_CORE_ERROR_INVAL;
}
if (!spursCreated)
{
if (!spurs->spuPortBits.bit_test_reset(spuPort) && _spurs::get_sdk_version() >= 0x180000)
{
return CELL_SPURS_CORE_ERROR_SRCH;
}
}
return CELL_OK;
}
void _spurs::handler_wait_ready(ppu_thread& ppu, vm::ptr<CellSpurs> spurs)
{
ensure(ppu_execute<&sys_lwmutex_lock>(ppu, spurs.ptr(&CellSpurs::mutex), 0) == 0);
static_cast<void>(ppu.test_stopped());
while (true)
{
if (spurs->handlerExiting)
{
ensure(ppu_execute<&sys_lwmutex_unlock>(ppu, spurs.ptr(&CellSpurs::mutex)) == 0);
static_cast<void>(ppu.test_stopped());
return sys_ppu_thread_exit(ppu, 0);
}
// Find a runnable workload
spurs->handlerDirty = 0;
if (spurs->exception == 0u)
{
bool foundRunnableWorkload = false;
for (u32 i = 0; i < 16; i++)
{
if (spurs->wklState1[i] == SPURS_WKL_STATE_RUNNABLE &&
std::bit_cast<u64>(spurs->wklInfo1[i].priority) != 0 &&
spurs->wklMaxContention[i] & 0x0F)
{
if (spurs->wklReadyCount1[i] ||
spurs->wklSignal1.load() & (0x8000u >> i) ||
(spurs->wklFlag.flag.load() == 0u &&
spurs->wklFlagReceiver == static_cast<u8>(i)))
{
foundRunnableWorkload = true;
break;
}
}
}
if (spurs->flags1 & SF1_32_WORKLOADS)
{
for (u32 i = 0; i < 16; i++)
{
if (spurs->wklState2[i] == SPURS_WKL_STATE_RUNNABLE &&
std::bit_cast<u64>(spurs->wklInfo2[i].priority) != 0 &&
spurs->wklMaxContention[i] & 0xF0)
{
if (spurs->wklIdleSpuCountOrReadyCount2[i] ||
spurs->wklSignal2.load() & (0x8000u >> i) ||
(spurs->wklFlag.flag.load() == 0u &&
spurs->wklFlagReceiver == static_cast<u8>(i) + 0x10))
{
foundRunnableWorkload = true;
break;
}
}
}
}
if (foundRunnableWorkload) {
break;
}
}
// If we reach it means there are no runnable workloads in this SPURS instance.
// Wait until some workload becomes ready.
spurs->handlerWaiting = 1;
if (spurs->handlerDirty == 0)
{
ensure(ppu_execute<&sys_lwcond_wait>(ppu, spurs.ptr(&CellSpurs::cond), 0) == 0);
static_cast<void>(ppu.test_stopped());
}
spurs->handlerWaiting = 0;
}
// If we reach here then a runnable workload was found
ensure(ppu_execute<&sys_lwmutex_unlock>(ppu, spurs.ptr(&CellSpurs::mutex)) == 0);
static_cast<void>(ppu.test_stopped());
}
void _spurs::handler_entry(ppu_thread& ppu, vm::ptr<CellSpurs> spurs)
{
if (spurs->flags & SAF_UNKNOWN_FLAG_30)
{
return sys_ppu_thread_exit(ppu, 0);
}
while (true)
{
if (spurs->flags1 & SF1_EXIT_IF_NO_WORK)
{
_spurs::handler_wait_ready(ppu, spurs);
}
ensure(sys_spu_thread_group_start(ppu, spurs->spuTG) == 0);
const s32 rc = sys_spu_thread_group_join(ppu, spurs->spuTG, vm::null, vm::null);
static_cast<void>(ppu.test_stopped());
if (rc + 0u != CELL_EFAULT)
{
static_cast<void>(ppu.test_stopped());
if (rc + 0u == CELL_ESTAT)
{
return sys_ppu_thread_exit(ppu, 0);
}
ensure(rc + 0u == CELL_EFAULT);
}
if ((spurs->flags1 & SF1_EXIT_IF_NO_WORK) == 0)
{
ensure((spurs->handlerExiting == 1));
return sys_ppu_thread_exit(ppu, 0);
}
}
}
s32 _spurs::create_handler(vm::ptr<CellSpurs> spurs, u32 ppuPriority)
{
struct handler_thread : ppu_thread
{
using ppu_thread::ppu_thread;
void non_task()
{
//BIND_FUNC(_spurs::handler_entry)(*this);
}
};
// auto eht = idm::make_ptr<ppu_thread, handler_thread>(std::string(spurs->prefix, spurs->prefixSize) + "SpursHdlr0", ppuPriority, 0x4000);
// spurs->ppu0 = eht->id;
// eht->gpr[3] = spurs.addr();
// eht->run();
return CELL_OK;
}
s32 _spurs::invoke_event_handlers(ppu_thread& ppu, vm::ptr<CellSpurs::EventPortMux> eventPortMux)
{
if (eventPortMux->reqPending.exchange(0))
{
for (auto node = eventPortMux->handlerList.exchange(vm::null); node; node = node->next)
{
node->handler(ppu, eventPortMux, node->data);
}
}
return CELL_OK;
}
s32 _spurs::wakeup_shutdown_completion_waiter(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 wid)
{
if (!spurs)
{
return CELL_SPURS_POLICY_MODULE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
{
return CELL_SPURS_POLICY_MODULE_ERROR_ALIGN;
}
if (wid >= spurs->max_workloads())
{
return CELL_SPURS_POLICY_MODULE_ERROR_INVAL;
}
if ((spurs->wklEnabled.load() & (0x80000000u >> wid)) == 0u)
{
return CELL_SPURS_POLICY_MODULE_ERROR_SRCH;
}
if (spurs->wklState(wid) != SPURS_WKL_STATE_REMOVABLE)
{
return CELL_SPURS_POLICY_MODULE_ERROR_STAT;
}
const auto wklF = wid < CELL_SPURS_MAX_WORKLOAD ? &spurs->wklF1[wid] : &spurs->wklF2[wid & 0x0F];
const auto wklEvent = &spurs->wklEvent(wid);
if (wklF->hook)
{
wklF->hook(ppu, spurs, wid, wklF->hookArg);
ensure((wklEvent->load() & 0x01));
ensure((wklEvent->load() & 0x02));
ensure((wklEvent->load() & 0x20) == 0);
wklEvent->fetch_or(0x20);
}
s32 rc = CELL_OK;
if (!wklF->hook || wklEvent->load() & 0x10)
{
ensure((wklF->x28 == 2u));
rc = sys_semaphore_post(ppu, static_cast<u32>(wklF->sem), 1);
static_cast<void>(ppu.test_stopped());
}
return rc;
}
void _spurs::event_helper_entry(ppu_thread& ppu, vm::ptr<CellSpurs> spurs)
{
vm::var<sys_event_t[]> events(8);
vm::var<u32> count;
while (true)
{
ensure(sys_event_queue_receive(ppu, spurs->eventQueue, vm::null, 0) == 0);
static_cast<void>(ppu.test_stopped());
const u64 event_src = ppu.gpr[4];
const u64 event_data1 = ppu.gpr[5];
const u64 event_data2 = ppu.gpr[6];
const u64 event_data3 = ppu.gpr[7];
if (event_src == SYS_SPU_THREAD_EVENT_EXCEPTION_KEY)
{
spurs->exception = 1;
events[0].source = event_src;
events[0].data1 = event_data1;
events[0].data2 = event_data2;
events[0].data3 = event_data3;
if (sys_event_queue_tryreceive(ppu, spurs->eventQueue, events + 1, 7, count) != CELL_OK)
{
continue;
}
// TODO: Examine LS and dump exception details
for (u32 i = 0; i < CELL_SPURS_MAX_WORKLOAD; i++)
{
sys_semaphore_post(ppu, static_cast<u32>(spurs->wklF1[i].sem), 1);
if (spurs->flags1 & SF1_32_WORKLOADS)
{
sys_semaphore_post(ppu, static_cast<u32>(spurs->wklF2[i].sem), 1);
}
}
static_cast<void>(ppu.test_stopped());
}
else
{
const u32 data0 = event_data2 & 0x00FFFFFF;
if (data0 == 1)
{
return;
}
else if (data0 < 1)
{
const u32 shutdownMask = static_cast<u32>(event_data3);
for (u32 wid = 0; wid < CELL_SPURS_MAX_WORKLOAD; wid++)
{
if (shutdownMask & (0x80000000u >> wid))
{
ensure(_spurs::wakeup_shutdown_completion_waiter(ppu, spurs, wid) == 0);
}
if ((spurs->flags1 & SF1_32_WORKLOADS) && (shutdownMask & (0x8000 >> wid)))
{
ensure(_spurs::wakeup_shutdown_completion_waiter(ppu, spurs, wid + 0x10) == 0);
}
}
}
else if (data0 == 2)
{
ensure(sys_semaphore_post(ppu, static_cast<u32>(spurs->semPrv), 1) == 0);
static_cast<void>(ppu.test_stopped());
}
else if (data0 == 3)
{
ensure(_spurs::invoke_event_handlers(ppu, spurs.ptr(&CellSpurs::eventPortMux)) == 0);
}
else
{
fmt::throw_exception("data0=0x%x", data0);
}
}
}
}
s32 _spurs::create_event_helper(ppu_thread& ppu, vm::ptr<CellSpurs> spurs, u32 ppuPriority)
{
if (s32 rc = _spurs::create_lv2_eq(ppu, spurs, spurs.ptr(&CellSpurs::eventQueue), spurs.ptr(&CellSpurs::spuPort), 0x2A, sys_event_queue_attribute_t{SYS_SYNC_PRIORITY, SYS_PPU_QUEUE, {"_spuPrv\0"_u64}}))
{
return rc;
}
if (sys_event_port_create(ppu, spurs.ptr(&CellSpurs::eventPort), SYS_EVENT_PORT_LOCAL, SYS_EVENT_PORT_NO_NAME))
{
if (_spurs::detach_lv2_eq(spurs, spurs->spuPort, true))
{
return CELL_SPURS_CORE_ERROR_AGAIN;
}
sys_event_queue_destroy(ppu, spurs->eventQueue, SYS_EVENT_QUEUE_DESTROY_FORCE);
return CELL_SPURS_CORE_ERROR_AGAIN;
}
if (sys_event_port_connect_local(ppu, spurs->eventPort, spurs->eventQueue))
{
sys_event_port_destroy(ppu, spurs->eventPort);
if (_spurs::detach_lv2_eq(spurs, spurs->spuPort, true))
{
return CELL_SPURS_CORE_ERROR_STAT;
}
sys_event_queue_destroy(ppu, spurs->eventQueue, SYS_EVENT_QUEUE_DESTROY_FORCE);
return CELL_SPURS_CORE_ERROR_STAT;
}
struct event_helper_thread : ppu_thread
{
using ppu_thread::ppu_thread;
void non_task()
{
//BIND_FUNC(_spurs::event_helper_entry)(*this);
}
};
//auto eht = idm::make_ptr<ppu_thread, event_helper_thread>(std::string(spurs->prefix, spurs->prefixSize) + "SpursHdlr1", ppuPriority, 0x8000);
//if (!eht)
{
sys_event_port_disconnect(ppu, spurs->eventPort);
sys_event_port_destroy(ppu, spurs->eventPort);
if (_spurs::detach_lv2_eq(spurs, spurs->spuPort, true))
{
return CELL_SPURS_CORE_ERROR_STAT;
}
sys_event_queue_destroy(ppu, spurs->eventQueue, SYS_EVENT_QUEUE_DESTROY_FORCE);
return CELL_SPURS_CORE_ERROR_STAT;
}
// eht->gpr[3] = spurs.addr();
// eht->run();
// spurs->ppu1 = eht->id;
return CELL_OK;
}
void _spurs::init_event_port_mux(vm::ptr<CellSpurs::EventPortMux> eventPortMux, u8 spuPort, u32 eventPort, u32 unknown)
{
memset(eventPortMux.get_ptr(), 0, sizeof(CellSpurs::EventPortMux));
eventPortMux->spuPort = spuPort;
eventPortMux->eventPort = eventPort;
eventPortMux->x08 = unknown;
}
s32 _spurs::add_default_syswkl(vm::ptr<CellSpurs> spurs, vm::cptr<u8> swlPriority, u32 swlMaxSpu, u32 swlIsPreem)
{
// TODO: Implement this
return CELL_OK;
}
s32 _spurs::finalize_spu(ppu_thread& ppu, vm::ptr<CellSpurs> spurs)
{
if (spurs->flags & SAF_UNKNOWN_FLAG_7 || spurs->flags & SAF_UNKNOWN_FLAG_8)
{
while (true)
{
ensure(sys_spu_thread_group_join(ppu, spurs->spuTG, vm::null, vm::null) + 0u == CELL_EFAULT);