Support CD Callback

This commit is contained in:
Björn Gaier 2024-06-14 20:53:30 +02:00
parent 96644c55b0
commit 52893a08fe
4 changed files with 26 additions and 15 deletions

View File

@ -4,14 +4,20 @@
namespace JabyEngine { namespace JabyEngine {
namespace Callback { namespace Callback {
namespace internal { namespace internal {
static void execute_callback(Thread::Handle thread_handle) { static void execute_callback(Thread::Handle thread_handle, uint32_t parm) {
if(CurrentThread::is_me(MainThread::Handle)) { if(CurrentThread::is_me(MainThread::Handle)) {
CurrentThread::replace_with(thread_handle); CurrentThread::replace_with(thread_handle);
CurrentThread::force_a0(parm);
} }
SysCall::ReturnFromException(); SysCall::ReturnFromException();
} }
static uint32_t resume_callback(Thread::Handle handle) {
SysCall::ChangeThread(handle);
asm("sw $a0, %0" : "=m"(handle));
return handle;
}
namespace VSync { namespace VSync {
static constexpr size_t StackSize = 64; static constexpr size_t StackSize = 64;
@ -20,18 +26,22 @@ namespace JabyEngine {
void routine(); void routine();
static void [[deprecated("Currently not in use")]] execute() { static void [[deprecated("Currently not in use")]] execute() {
execute_callback(VSync::thread_handle); execute_callback(VSync::thread_handle, 0);
} }
} }
namespace CD { namespace CD {
static constexpr size_t StackSize = 256; static constexpr size_t StackSize = 256;
extern SysCall::ThreadHandle thread_handle; extern Thread::Handle thread_handle;
extern uint32_t stack[StackSize]; extern uint32_t stack[StackSize];
static void execute() { static void execute(uint32_t parm) {
execute_callback(CD::thread_handle); execute_callback(CD::thread_handle, parm);
}
static uint32_t resume() {
return resume_callback(MainThread::Handle);
} }
} }
} }

View File

@ -14,8 +14,8 @@ namespace JabyEngine {
} }
template<size_t N> template<size_t N>
static Handle create(void(*function)(), uint32_t(&stack)[N]) { static Handle create(void(*function)(uint32_t), uint32_t(&stack)[N]) {
return SysCall::OpenThread(function, &stack[N - 1], SysCall::get_gp()); return SysCall::OpenThread(reinterpret_cast<void(*)()>(function), &stack[N - 1], SysCall::get_gp());
} }
static void set_kernel_mode_for(SysCall::ThreadHandle handle) { static void set_kernel_mode_for(SysCall::ThreadHandle handle) {
@ -32,6 +32,10 @@ namespace JabyEngine {
return table_of_tables.processes->current_tcb->epc; return table_of_tables.processes->current_tcb->epc;
} }
static void force_a0(uint32_t a0) {
table_of_tables.processes->current_tcb->reg[4] = a0;
}
static bool is_me(Thread::Handle handle) { static bool is_me(Thread::Handle handle) {
return table_of_tables.processes->current_tcb == &table_of_tables.threads[Thread::idx_from_handle(handle)]; return table_of_tables.processes->current_tcb == &table_of_tables.threads[Thread::idx_from_handle(handle)];
} }

View File

@ -16,9 +16,7 @@ namespace JabyEngine {
); );
Thread::set_user_mode_for(InternalCallback::VSync::thread_handle);*/ Thread::set_user_mode_for(InternalCallback::VSync::thread_handle);*/
InternalCallback::CD::thread_handle = Thread::create( InternalCallback::CD::thread_handle = Thread::create(JabyEngine::CD::internal::IRQ::data_ready_handler, InternalCallback::CD::stack);
reinterpret_cast<void(*)()>(JabyEngine::CD::internal::IRQ::data_ready_handler),
InternalCallback::CD::stack);
Thread::set_user_mode_for(InternalCallback::CD::thread_handle); Thread::set_user_mode_for(InternalCallback::CD::thread_handle);
SysCall::ExitCriticalSection(); SysCall::ExitCriticalSection();
} }

View File

@ -104,7 +104,6 @@ namespace JabyEngine {
static void handler(uint32_t) { static void handler(uint32_t) {
const auto old_status = CD_IO::IndexStatus.read(); const auto old_status = CD_IO::IndexStatus.read();
void (*exit_routine)() = Callback::internal::CD::execute;
CD_IO::PortIndex1::change_to(); CD_IO::PortIndex1::change_to();
const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag); const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);
@ -151,13 +150,13 @@ namespace JabyEngine {
// No masking required because we can only write bit 0 - 2 // No masking required because we can only write bit 0 - 2
CD_IO::IndexStatus.write(old_status); CD_IO::IndexStatus.write(old_status);
exit_routine(); Callback::internal::CD::execute(cur_irq);
} }
void data_ready_handler(uint32_t data) { void data_ready_handler(uint32_t data) {
while(true) { while(true) {
printf("Data: %i\n", data); printf("Data: %i\n", data);
SysCall::ChangeThread(MainThread::Handle); data = Callback::internal::CD::resume();
} }
} }
} }