Skip to content

Commit ed059b2

Browse files
committed
Use PSP variant psp1
System functions on PSP are very sensitive to where stack is. So let system functions handle it
1 parent 06b4cdc commit ed059b2

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

libco/libco.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ void genode_free_secondary_stack(void *stack);
2929
#include "ppc.c"
3030
#elif defined(__aarch64__)
3131
#include "aarch64.c"
32-
#elif defined(__mips__)
33-
#include "mips.c"
32+
#elif defined PSP
33+
#include "psp1.c"
3434
#elif defined VITA
3535
#include "scefiber.c"
36+
#elif defined(__mips__)
37+
#include "mips.c"
3638
#elif defined(__ARM_EABI__) || defined(__arm__)
3739
#include "armeabi.c"
3840
#else

libco/psp1.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#define LIBCO_C
2+
#include "libco.h"
3+
4+
#include <stdlib.h>
5+
#include <pspthreadman.h>
6+
7+
/* Since cothread_t is a void pointer it must contain an address. We can't return a reference to a local variable
8+
* because it would go out of scope, so we create a static variable instead so we can return a reference to it.
9+
*/
10+
static SceUID active_thread_id = 0;
11+
12+
cothread_t co_active()
13+
{
14+
active_thread_id = sceKernelGetThreadId();
15+
return &active_thread_id;
16+
}
17+
18+
cothread_t co_create(unsigned int size, void (*entrypoint)(void))
19+
{
20+
/* Similar scenario as with active_thread_id except there will only be one active_thread_id while there could be many
21+
* new threads each with their own handle, so we create them on the heap instead and delete them manually when they're
22+
* no longer needed in co_delete().
23+
*/
24+
cothread_t handle = malloc(sizeof(cothread_t));
25+
26+
/* SceKernelThreadEntry has a different signature than entrypoint, but in practice this seems to work */
27+
SceUID new_thread_id = sceKernelCreateThread("cothread", (SceKernelThreadEntry)entrypoint, 0x12, size, 0, NULL);
28+
sceKernelStartThread(new_thread_id, 0, NULL);
29+
30+
*(SceUID *)handle = new_thread_id;
31+
return handle;
32+
}
33+
34+
void co_delete(cothread_t handle)
35+
{
36+
sceKernelTerminateDeleteThread(*(SceUID *)handle);
37+
free(handle);
38+
}
39+
40+
void co_switch(cothread_t handle)
41+
{
42+
sceKernelWakeupThread(*(SceUID *)handle);
43+
/* Sleep the currently active thread so the new thread can start */
44+
sceKernelSleepThread();
45+
}

0 commit comments

Comments
 (0)