summaryrefslogtreecommitdiff
path: root/libco/psp2.c
diff options
context:
space:
mode:
authorDavid Guillen Fandos2021-03-08 18:44:03 +0100
committerDavid Guillen Fandos2021-03-08 18:44:03 +0100
commit56dc6ecb70e6fc76d32d6a7194acb273b76bfe0e (patch)
treecf3b14a8d1bc593248398d0c544251ea8987b40e /libco/psp2.c
parent02e35339ee89f92d346d290c24497bbbae59ea79 (diff)
downloadpicogpsp-56dc6ecb70e6fc76d32d6a7194acb273b76bfe0e.tar.gz
picogpsp-56dc6ecb70e6fc76d32d6a7194acb273b76bfe0e.tar.bz2
picogpsp-56dc6ecb70e6fc76d32d6a7194acb273b76bfe0e.zip
Remove libco
This removes libco and all the usages of it (+pthreads). Rewired all dynarecs and interpreter to return after every frame so that libretro can process events. This required to make dynarec re-entrant. Dynarecs were updated to check for new frame on every update (IRQ, cycle exhaustion, I/O write, etc). The performance impact of doing so should be minimal (and definitely outweight the libco gains). While at it, fixed small issues to get a bit more perf: arm dynarec was not idling correctly, mips was using stack when not needed, etc. Tested on PSP (mips), OGA (armv7), Linux (x86 and interpreter). Not tested on Android though.
Diffstat (limited to 'libco/psp2.c')
-rw-r--r--libco/psp2.c116
1 files changed, 0 insertions, 116 deletions
diff --git a/libco/psp2.c b/libco/psp2.c
deleted file mode 100644
index 3ab1bc7..0000000
--- a/libco/psp2.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- libco.arm (2016-08-14)
- author: frangarcj
- license: public domain
-*/
-
-#define LIBCO_C
-#include "libco.h"
-
-#include <assert.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <psp2/kernel/sysmem.h>
-#include <stdio.h>
-#include <string.h>
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-static inline int align(int x, int n) {
- return (((x >> n) + 1) << n );
-}
-#define FOUR_KB_ALIGN(x) align(x, 12)
-#define MB_ALIGN(x) align(x, 20)
-
-static thread_local unsigned long co_active_buffer[64];
-static thread_local cothread_t co_active_handle = 0;
-static void (*co_swap)(cothread_t, cothread_t) = 0;
-static int block;
-static uint32_t co_swap_function[] = {
- 0xe8a16ff0, /* stmia r1!, {r4-r11,sp,lr} */
- 0xe8b0aff0, /* ldmia r0!, {r4-r11,sp,pc} */
- 0xe12fff1e, /* bx lr */
-};
-
-void co_init() {
- int ret;
- void *base;
-
- block = sceKernelAllocMemBlockForVM("libco", MB_ALIGN(FOUR_KB_ALIGN(sizeof co_swap_function)));
- if (block < 0)
- {
- return;
- }
-
- // get base address
- ret = sceKernelGetMemBlockBase(block, &base);
- if (ret < 0)
- {
- return;
- }
-
- // set domain to be writable by user
- ret = sceKernelOpenVMDomain();
- if (ret < 0)
- {
- return;
- }
-
-
- memcpy(base,co_swap_function,sizeof co_swap_function);
-
- // set domain back to read-only
- ret = sceKernelCloseVMDomain();
- if (ret < 0)
- {
- return;
- }
-
- // flush icache
- ret = sceKernelSyncVMDomain(block, base, MB_ALIGN(FOUR_KB_ALIGN(sizeof co_swap_function)));
- if (ret < 0)
- {
- return;
- }
-
- co_swap = (void (*)(cothread_t, cothread_t))base;
-
-
-}
-
-cothread_t co_active() {
- if(!co_active_handle) co_active_handle = &co_active_buffer;
- return co_active_handle;
-}
-
-cothread_t co_create(unsigned int size, void (*entrypoint)(void)) {
- unsigned long* handle = 0;
- if(!co_swap) {
- co_init();
- }
- if(!co_active_handle) co_active_handle = &co_active_buffer;
- size += 256;
- size &= ~15;
-
- if((handle = (unsigned long*)malloc(size))) {
- unsigned long* p = (unsigned long*)((unsigned char*)handle + size);
- handle[8] = (unsigned long)p;
- handle[9] = (unsigned long)entrypoint;
- }
-
- return handle;
-}
-
-void co_delete(cothread_t handle) {
- free(handle);
-}
-
-void co_switch(cothread_t handle) {
- cothread_t co_previous_handle = co_active_handle;
- co_swap(co_active_handle = handle, co_previous_handle);
-}
-
-#ifdef __cplusplus
-}
-#endif