Support VSync callback

This commit is contained in:
2024-05-15 21:43:12 +02:00
parent 3c0cc3bb6a
commit deb5bf8442
11 changed files with 156 additions and 49 deletions

View File

@@ -0,0 +1,20 @@
#pragma once
#include "syscalls.hpp"
namespace JabyEngine {
namespace Callback {
struct VSyncCallback {
using Function = void (*)();
static Function callback;
static void install(Function function) {
VSyncCallback::callback = function;
}
static void uninstall() {
VSyncCallback::install(nullptr);
}
};
}
}

View File

@@ -118,6 +118,7 @@ namespace JabyEngine {
typedef InterruptVerifierResult (*InterruptVerifier)();
typedef uint32_t (*InterruptHandler)(uint32_t);
using ThreadHandle = uint32_t;
#pragma pack(push, 1)
struct InterrupCallback {
@@ -143,28 +144,13 @@ namespace JabyEngine {
return __syscall_function_cast(Table_A, void*(*)(void*, const void*, size_t))(dst, src, len);
}
static __always_inline uint32_t OpenTh(void (*thread_func)(), uint32_t* stack_ptr, uint32_t* gp) {
static __always_inline ThreadHandle OpenThread(void (*thread_func)(), uint32_t* stack_ptr, uint32_t* gp) {
register uint32_t FuncID asm("t1") = 0x0E;
__asm__ volatile("" : "=r"(FuncID) : "r"(FuncID));
return __syscall_function_cast(Table_B, uint32_t(*)(void(*)(), uint32_t*, uint32_t*))(thread_func, stack_ptr, gp);
return __syscall_function_cast(Table_B, ThreadHandle(*)(void(*)(), uint32_t*, uint32_t*))(thread_func, stack_ptr, gp);
}
static __always_inline uint32_t ChangeTh(uint32_t thread) {
register uint32_t FuncID asm("t1") = 0x10;
__asm__ volatile("" : "=r"(FuncID) : "r"(FuncID));
return __syscall_function_cast(Table_B, uint32_t(*)(uint32_t))(thread);
}
static __always_inline int changeThreadSubFunction(uint32_t address) {
register int n asm("a0") = 3;
register int tcb asm("a1") = address;
register int r asm("v0");
__asm__ volatile("syscall\n" : "=r"(r) : "r"(n), "r"(tcb) : "memory");
return r;
}
static __always_inline void InitPad(uint8_t *portA, uint32_t portASize, uint8_t *portB, uint32_t portBSize) {
register uint32_t FuncID asm("t1") = 0x12;
__asm__ volatile("" : "=r"(FuncID) : "r"(FuncID));

View File

@@ -0,0 +1,43 @@
#pragma once
#include "syscalls.hpp"
namespace JabyEngine {
struct Thread {
static constexpr uint32_t idx_from_handle(SysCall::ThreadHandle thread) {
return thread & 0xFFFF;
}
static void prepare_next(SysCall::ThreadHandle thread) {
table_of_tables.processes->current_tcb = &table_of_tables.threads[idx_from_handle(thread)];
}
static void execute_next() {
SysCall::ReturnFromException();
}
static void set_kernel_mode_for(SysCall::ThreadHandle handle) {
table_of_tables.threads[idx_from_handle(handle)].sr = 0x0;
}
static void set_user_mode_for(SysCall::ThreadHandle handle) {
table_of_tables.threads[idx_from_handle(handle)].sr = 0x40000404;
}
};
struct MainThread {
static void prepare_if_main(SysCall::ThreadHandle handle) {
if(table_of_tables.processes->current_tcb == &table_of_tables.threads[0]) {
Thread::prepare_next(handle);
}
}
static void prepare_restore() {
Thread::prepare_next(0);
}
static void restore() {
MainThread::prepare_restore();
Thread::execute_next();
}
};
}