From 074e2d073f9832815668a8f5352b123fbd59aee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gaier?= Date: Fri, 6 Oct 2023 10:27:03 +0200 Subject: [PATCH] Turn SysCalls into a C++ file --- include/PSX/System/syscalls.h | 175 ---------------------- include/PSX/System/syscalls.hpp | 167 +++++++++++++++++++++ include/PSX/jabyengine_defines.h | 4 + include/stdio.h | 7 +- lib/RebuildTarget.mk | 2 +- src/Library/src/BootLoader/cd_boot.cpp | 10 +- src/Library/src/BootLoader/gpu_boot.cpp | 9 +- src/Library/src/BootLoader/timer_boot.cpp | 10 +- src/Library/src/CD/cd.cpp | 27 ++-- src/Library/src/GPU/gpu.cpp | 21 +-- src/Library/src/Timer/high_res_timer.cpp | 17 ++- src/Library/src/syscall_printf.s | 6 +- 12 files changed, 228 insertions(+), 227 deletions(-) delete mode 100644 include/PSX/System/syscalls.h create mode 100644 include/PSX/System/syscalls.hpp diff --git a/include/PSX/System/syscalls.h b/include/PSX/System/syscalls.h deleted file mode 100644 index 38b3bac2..00000000 --- a/include/PSX/System/syscalls.h +++ /dev/null @@ -1,175 +0,0 @@ -#ifndef __JABYENGINE_SYSCALLS__H -#define __JABYENGINE_SYSCALLS__H -#include "../jabyengine_defines.h" - -/* -R0 zr Constant Zero -R1 at Reserved for the assembler -R2-R3 v0-v1 Values for results and expression evaluation -R4-R7 a0-a3 Arguments -R8-R15 t0-t7 Temporaries (not preserved across call) -R16-R23 s0-s7 Saved (preserved across call) -R24-R25 t8-t9 More temporaries (not preserved across call) -R26-R27 k0-k1 Reserved for OS Kernel -R28 gp Global Pointer -R29 sp Stack Pointer -R30 fp Frame Pointer -R31 ra Return address (set by function call) -*/ - -static __constexpr const uint32_t __syscall_Table_A = 0xA0; -static __constexpr const uint32_t __syscall_Table_B = 0xB0; -static __constexpr const uint32_t __syscall_Table_C = 0xC0; - -enum __syscall_PriorityChain { - CdromDmaIrq = 0, - CdromIoIrq = 0, - SyscallException = 0, - - CardSpecificIrq = 1, - VblankIrq = 1, - Timer2Irq = 1, - Timer1Irq = 1, - Timer0Irq = 1, - - PadCardIrq = 2, - - DefInt = 3 -}; - -enum InterruptVerifierResult { - SkipHandler = 0, - ExecuteHandler = 1 -}; - -typedef InterruptVerifierResult (*InterruptVerifier)(); -typedef uint32_t (*InterruptHandler)(uint32_t); - -#pragma pack(push, 1) -struct InterrupCallback { - struct InterrupCallback* next; - InterruptHandler handler_function; - InterruptVerifier verifier_function; - uint32_t notUsed; -}; -#pragma pack(pop) - -#ifdef __cplusplus - #define __syscall_function_cast(table, ...) reinterpret_cast<__VA_ARGS__>(table) - extern "C" { -#else - #define __syscall_function_cast(table, ...) ((__VA_ARGS__)(void*)table) -#endif - -static __always_inline void* __syscall_memcpy(void *dst, const void *src, size_t len) { - register uint32_t FuncID asm("t1") = 0x2A; - __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); - - return __syscall_function_cast(__syscall_Table_A, void*(*)(void*, const void*, size_t))(dst, src, len); -} - -static __always_inline void __syscall_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)); - - __syscall_function_cast(__syscall_Table_B, void(*)(uint8_t*, uint32_t, uint8_t*, uint32_t))(portA, portASize, portB, portBSize); -} - -static __always_inline void __syscall_StartPad() { - register uint32_t FuncID asm("t1") = 0x13; - __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); - - __syscall_function_cast(__syscall_Table_B, void(*)())(); -} - -static __always_inline void __syscall_StopPad() { - register uint32_t FuncID asm("t1") = 0x14; - __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); - - __syscall_function_cast(__syscall_Table_B, void(*)())(); -} - -static __always_inline void __syscall_ChangeClearPad(int32_t _reserved) { - register uint32_t FuncID asm("t1") = 0x5B; - __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); - - __syscall_function_cast(__syscall_Table_B, void(*)(int32_t))(_reserved); -} - -static __always_inline void [[noreturn]] __syscall_ReturnFromException() { - register uint32_t FuncID asm("t1") = 0x17; - __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); - - __syscall_function_cast(__syscall_Table_B, void(*)())(); -} - -static __always_inline int __syscall_SysEnqIntRP(enum __syscall_PriorityChain prio, struct InterrupCallback* interElm) { - register uint32_t FuncID asm("t1") = 0x02; - __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); - - return __syscall_function_cast(__syscall_Table_C, int(*)(enum __syscall_PriorityChain prio, struct InterrupCallback *interElm))(prio, interElm); -} - -static __always_inline int __syscall_SysDeqIntRP(enum __syscall_PriorityChain prio, struct InterrupCallback *interElm) { - register uint32_t FuncID asm("t1") = 0x03; - __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); - - return __syscall_function_cast(__syscall_Table_C, int(*)(enum __syscall_PriorityChain prio, struct InterrupCallback *interElm))(prio, interElm); -} - -static __always_inline uint32_t __syscall_EnterCriticalSection() { - register uint32_t FuncID asm("a0") = 0x01; - register uint32_t returnValue asm("v0"); - - __asm__ volatile("syscall" : "=r"(FuncID), "=r"(returnValue) : "r"(FuncID) : "at", "v1", "a1", "a2", "a3", "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9", "memory"); - return returnValue; -} - -static __always_inline void __syscall_ExitCriticalSection() { - register uint32_t FuncID asm("a0") = 0x02; - - __asm__ volatile("syscall" : "=r"(FuncID) : "r"(FuncID) : "at", "v0", "v1", "a1", "a2", "a3", "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9", "memory"); -} - -static __always_inline void __syscall__DeliverEvent(uint32_t classId, uint32_t spec) { - register uint32_t FuncID asm("t1") = 0x07; - - __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); - __syscall_function_cast(__syscall_Table_B, void (*)(uint32_t, uint32_t))(classId, spec); -} - -static __always_inline uint32_t __syscall_OpenEvent(uint32_t classId, uint32_t spec, uint32_t mode, void (*handler)()) { - register uint32_t FuncID asm("t1") = 0x08; - - __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); - return __syscall_function_cast(__syscall_Table_B, uint32_t(*)(uint32_t, uint32_t, uint32_t, void(*)()))(classId, spec, mode, handler); -} - -static __always_inline int __syscall_CloseEvent(uint32_t event) { - register uint32_t FuncID asm("t1") = 0x09; - - __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); - return __syscall_function_cast(__syscall_Table_B, uint32_t(*)(uint32_t))(event); -} - -static __always_inline int __syscall_TestEvent(uint32_t event) { - register uint32_t FuncID asm("t1") = 0x0B; - - __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); - return __syscall_function_cast(__syscall_Table_B, int (*)(uint32_t))(event); -} - -static __always_inline int __syscall_EnableEvent(uint32_t event) { - register uint32_t FuncID asm("t1") = 0x0C; - - __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); - return __syscall_function_cast(__syscall_Table_B, int (*)(uint32_t))(event); -} - -void __syscall_printf(const char* txt, ...); - -#ifdef __cplusplus -} -#endif - -#endif //!__JABYENGINE_SYSCALLS__H \ No newline at end of file diff --git a/include/PSX/System/syscalls.hpp b/include/PSX/System/syscalls.hpp new file mode 100644 index 00000000..d42cf6af --- /dev/null +++ b/include/PSX/System/syscalls.hpp @@ -0,0 +1,167 @@ +#pragma once +#include "../jabyengine_defines.h" + +/* +R0 zr Constant Zero +R1 at Reserved for the assembler +R2-R3 v0-v1 Values for results and expression evaluation +R4-R7 a0-a3 Arguments +R8-R15 t0-t7 Temporaries (not preserved across call) +R16-R23 s0-s7 Saved (preserved across call) +R24-R25 t8-t9 More temporaries (not preserved across call) +R26-R27 k0-k1 Reserved for OS Kernel +R28 gp Global Pointer +R29 sp Stack Pointer +R30 fp Frame Pointer +R31 ra Return address (set by function call) +*/ + +namespace JabyEngine { + namespace SysCall { + static constexpr const uint32_t Table_A = 0xA0; + static constexpr const uint32_t Table_B = 0xB0; + static constexpr const uint32_t Table_C = 0xC0; + + enum struct Priority { + CdromDmaIrq = 0, + CdromIoIrq = 0, + SyscallException = 0, + + CardSpecificIrq = 1, + VblankIrq = 1, + Timer2Irq = 1, + Timer1Irq = 1, + Timer0Irq = 1, + + PadCardIrq = 2, + + DefInt = 3 + }; + + enum InterruptVerifierResult { + SkipHandler = 0, + ExecuteHandler = 1 + }; + + typedef InterruptVerifierResult (*InterruptVerifier)(); + typedef uint32_t (*InterruptHandler)(uint32_t); + + #pragma pack(push, 1) + struct InterrupCallback { + struct InterrupCallback* next; + InterruptHandler handler_function; + InterruptVerifier verifier_function; + uint32_t notUsed; + }; + #pragma pack(pop) + + #define __syscall_function_cast(table, ...) reinterpret_cast<__VA_ARGS__>(table) + + static __always_inline void* memcpy(void *dst, const void *src, size_t len) { + register uint32_t FuncID asm("t1") = 0x2A; + __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); + + return __syscall_function_cast(Table_A, void*(*)(void*, const void*, size_t))(dst, src, len); + } + + 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)); + + __syscall_function_cast(Table_B, void(*)(uint8_t*, uint32_t, uint8_t*, uint32_t))(portA, portASize, portB, portBSize); + } + + static __always_inline void StartPad() { + register uint32_t FuncID asm("t1") = 0x13; + __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); + + __syscall_function_cast(Table_B, void(*)())(); + } + + static __always_inline void StopPad() { + register uint32_t FuncID asm("t1") = 0x14; + __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); + + __syscall_function_cast(Table_B, void(*)())(); + } + + static __always_inline void ChangeClearPad(int32_t _reserved) { + register uint32_t FuncID asm("t1") = 0x5B; + __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); + + __syscall_function_cast(Table_B, void(*)(int32_t))(_reserved); + } + + static __always_inline void [[noreturn]] ReturnFromException() { + register uint32_t FuncID asm("t1") = 0x17; + __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); + + __syscall_function_cast(Table_B, void(*)())(); + } + + static __always_inline int SysEnqIntRP(Priority prio, InterrupCallback* interElm) { + register uint32_t FuncID asm("t1") = 0x02; + __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); + + return __syscall_function_cast(Table_C, int(*)(Priority prio, InterrupCallback *interElm))(prio, interElm); + } + + static __always_inline int SysDeqIntRP(Priority prio, InterrupCallback *interElm) { + register uint32_t FuncID asm("t1") = 0x03; + __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); + + return __syscall_function_cast(Table_C, int(*)(Priority prio, InterrupCallback *interElm))(prio, interElm); + } + + static __always_inline uint32_t EnterCriticalSection() { + register uint32_t FuncID asm("a0") = 0x01; + register uint32_t returnValue asm("v0"); + + __asm__ volatile("syscall" : "=r"(FuncID), "=r"(returnValue) : "r"(FuncID) : "at", "v1", "a1", "a2", "a3", "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9", "memory"); + return returnValue; + } + + static __always_inline void ExitCriticalSection() { + register uint32_t FuncID asm("a0") = 0x02; + + __asm__ volatile("syscall" : "=r"(FuncID) : "r"(FuncID) : "at", "v0", "v1", "a1", "a2", "a3", "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9", "memory"); + } + + static __always_inline void DeliverEvent(uint32_t classId, uint32_t spec) { + register uint32_t FuncID asm("t1") = 0x07; + + __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); + __syscall_function_cast(Table_B, void (*)(uint32_t, uint32_t))(classId, spec); + } + + static __always_inline uint32_t OpenEvent(uint32_t classId, uint32_t spec, uint32_t mode, void (*handler)()) { + register uint32_t FuncID asm("t1") = 0x08; + + __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); + return __syscall_function_cast(Table_B, uint32_t(*)(uint32_t, uint32_t, uint32_t, void(*)()))(classId, spec, mode, handler); + } + + static __always_inline int CloseEvent(uint32_t event) { + register uint32_t FuncID asm("t1") = 0x09; + + __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); + return __syscall_function_cast(Table_B, uint32_t(*)(uint32_t))(event); + } + + static __always_inline int TestEvent(uint32_t event) { + register uint32_t FuncID asm("t1") = 0x0B; + + __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); + return __syscall_function_cast(Table_B, int (*)(uint32_t))(event); + } + + static __always_inline int EnableEvent(uint32_t event) { + register uint32_t FuncID asm("t1") = 0x0C; + + __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); + return __syscall_function_cast(Table_B, int (*)(uint32_t))(event); + } + + void printf(const char* txt, ...); + } +} \ No newline at end of file diff --git a/include/PSX/jabyengine_defines.h b/include/PSX/jabyengine_defines.h index 224f1708..b5be8173 100644 --- a/include/PSX/jabyengine_defines.h +++ b/include/PSX/jabyengine_defines.h @@ -12,7 +12,11 @@ #ifdef __cplusplus #define __constexpr constexpr + #define START_C_FUNCTIONS extern "C" { + #define END_C_FUNCTIONS } #else #define __constexpr + #define START_C_FUNCTIONS + #define END_C_FUNCTIONS #endif #endif //!__JABYENGINE_DEFINES__H__ \ No newline at end of file diff --git a/include/stdio.h b/include/stdio.h index cb03ac80..a65f8bdb 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -1,7 +1,8 @@ #ifndef __STDIO__H #define __STDIO__H -#include "PSX/System/syscalls.h" - -#define printf __syscall_printf +#include "PSX/jabyengine_defines.h" +START_C_FUNCTIONS + int printf(const char* txt, ...) asm("_ZN10JabyEngine7SysCall6printfEPKcz"); +END_C_FUNCTIONS #endif //!__STDIO__H \ No newline at end of file diff --git a/lib/RebuildTarget.mk b/lib/RebuildTarget.mk index 59c7d2a0..217368e9 100644 --- a/lib/RebuildTarget.mk +++ b/lib/RebuildTarget.mk @@ -1 +1 @@ -rebuild: |clean all \ No newline at end of file +rebuild: | clean all \ No newline at end of file diff --git a/src/Library/src/BootLoader/cd_boot.cpp b/src/Library/src/BootLoader/cd_boot.cpp index ef78618b..bf73e1ae 100644 --- a/src/Library/src/BootLoader/cd_boot.cpp +++ b/src/Library/src/BootLoader/cd_boot.cpp @@ -2,12 +2,12 @@ #include "../../internal-include/CD/cd_internal.hpp" #include #include -#include +#include namespace JabyEngine { namespace CD { namespace internal { - extern InterrupCallback callback; + extern SysCall::InterrupCallback callback; } } @@ -21,11 +21,11 @@ namespace JabyEngine { static constexpr auto DebugScale = 1.0; __debug_boot_color_at(::JabyEngine::GPU::Color24::White(), DebugX, DebugY, DebugScale); - __syscall_EnterCriticalSection(); + SysCall::EnterCriticalSection(); Memory_IO::COM_DELAY.write(Memory_IO::COM_DELAY::create()); Memory_IO::CD_DELAY.write(Memory_IO::CD_DELAY::create()); - __syscall_SysEnqIntRP(CdromIoIrq, &::JabyEngine::CD::internal::callback); + SysCall::SysEnqIntRP(SysCall::Priority::CdromIoIrq, &::JabyEngine::CD::internal::callback); CD_IO::PortIndex1::change_to(); CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag); @@ -34,7 +34,7 @@ namespace JabyEngine { Interrupt::enable_irq(Interrupt::CDROM); Interrupt::ack_irq(Interrupt::CDROM); - __syscall_ExitCriticalSection(); + SysCall::ExitCriticalSection(); __debug_boot_color_at(::JabyEngine::GPU::Color24::Red(), DebugX, DebugY, DebugScale); CD_IO::PortIndex0::change_to(); diff --git a/src/Library/src/BootLoader/gpu_boot.cpp b/src/Library/src/BootLoader/gpu_boot.cpp index 22206f0c..55f86c02 100644 --- a/src/Library/src/BootLoader/gpu_boot.cpp +++ b/src/Library/src/BootLoader/gpu_boot.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #ifdef JABYENGINE_PAL @@ -16,7 +17,7 @@ extern "C" uint32_t __boot_loader_end; namespace JabyEngine { namespace GPU { namespace internal { - extern InterrupCallback callback; + extern SysCall::InterrupCallback callback; } } @@ -72,10 +73,10 @@ namespace JabyEngine { GPU::internal::wait_ready_for_CMD(); GPU::internal::quick_fill_fast(Color24::Black(), {PositionU16::create(0, 0), SizeU16::create(Display::Width, Display::Height)}); - __syscall_EnterCriticalSection(); - __syscall_SysEnqIntRP(VblankIrq, &::JabyEngine::GPU::internal::callback); + SysCall::EnterCriticalSection(); + SysCall::SysEnqIntRP(SysCall::Priority::VblankIrq, &::JabyEngine::GPU::internal::callback); Interrupt::enable_irq(Interrupt::VBlank); - __syscall_ExitCriticalSection(); + SysCall::ExitCriticalSection(); } } } diff --git a/src/Library/src/BootLoader/timer_boot.cpp b/src/Library/src/BootLoader/timer_boot.cpp index 9518173c..e0be68fa 100644 --- a/src/Library/src/BootLoader/timer_boot.cpp +++ b/src/Library/src/BootLoader/timer_boot.cpp @@ -1,12 +1,12 @@ #include -#include +#include #define private public #include #undef private namespace JabyEngine { namespace Timer { - extern InterrupCallback IRQCallback; + extern SysCall::InterrupCallback IRQCallback; } namespace boot { @@ -22,9 +22,9 @@ namespace JabyEngine { // Having the interrupt fire every 10ms will slow us down slightly so we only do it on demand Interrupt::disable_irq(Interrupt::Timer2); - __syscall_EnterCriticalSection(); - __syscall_SysEnqIntRP(Timer2Irq, &IRQCallback); - __syscall_ExitCriticalSection(); + SysCall::EnterCriticalSection(); + SysCall::SysEnqIntRP(SysCall::Priority::Timer2Irq, &IRQCallback); + SysCall::ExitCriticalSection(); Counter2.set_target_value(HighResTime::TicksFor10ms); Counter2.set_mode(Mode); diff --git a/src/Library/src/CD/cd.cpp b/src/Library/src/CD/cd.cpp index f998ad34..a1f0e168 100644 --- a/src/Library/src/CD/cd.cpp +++ b/src/Library/src/CD/cd.cpp @@ -1,26 +1,26 @@ #include "../../internal-include/CD/cd_internal.hpp" #include #include -#include +#include namespace JabyEngine { namespace CD { namespace internal { static constexpr auto DataSectorMode = CD_IO::Mode::from(CD_IO::Mode::DoubleSpeed, CD_IO::Mode::DataSector); - static InterruptVerifierResult interrupt_verifier(); - static void interrupt_handler(uint32_t); + static SysCall::InterruptVerifierResult interrupt_verifier(); + static uint32_t interrupt_handler(uint32_t); static SectorBufferAllocator sector_allocator; static uint32_t cur_lba; static uint32_t dst_lba; - CD_IO::Interrupt::Type last_interrupt = CD_IO::Interrupt::Type::None; - uint8_t cmd_interrupt_bit = 0; - State current_state = State::Free; - InterrupCallback callback = { + CD_IO::Interrupt::Type last_interrupt = CD_IO::Interrupt::Type::None; + uint8_t cmd_interrupt_bit = 0; + State current_state = State::Free; + SysCall::InterrupCallback callback = { .next = nullptr, - .handler_function = reinterpret_cast(interrupt_handler), + .handler_function = interrupt_handler, .verifier_function = interrupt_verifier }; @@ -68,17 +68,17 @@ namespace JabyEngine { // Doesn't seem to important when we can use DMA } - static InterruptVerifierResult interrupt_verifier() { + static SysCall::InterruptVerifierResult interrupt_verifier() { if(Interrupt::is_irq(Interrupt::CDROM)) { - return InterruptVerifierResult::ExecuteHandler; + return SysCall::InterruptVerifierResult::ExecuteHandler; } else { - return InterruptVerifierResult::SkipHandler; + return SysCall::InterruptVerifierResult::SkipHandler; } } - static void interrupt_handler(uint32_t) { + static uint32_t interrupt_handler(uint32_t) { const auto old_status = CD_IO::IndexStatus.read(); CD_IO::PortIndex1::change_to(); @@ -114,7 +114,8 @@ namespace JabyEngine { // No masking required because we can only write bit 0 - 2 CD_IO::IndexStatus.write(old_status); Interrupt::ack_irq(Interrupt::CDROM); - __syscall_ReturnFromException(); + SysCall::ReturnFromException(); + __builtin_unreachable(); } void read_file(AutoLBAEntry file_info, const SectorBufferAllocator& buffer_allocator) { diff --git a/src/Library/src/GPU/gpu.cpp b/src/Library/src/GPU/gpu.cpp index 2ce7df98..e9029b29 100644 --- a/src/Library/src/GPU/gpu.cpp +++ b/src/Library/src/GPU/gpu.cpp @@ -4,40 +4,41 @@ #include #undef private #include -#include +#include namespace JabyEngine { namespace GPU { uint8_t Display :: current_id = 1; //< Setup will call exchange and set it to 0 namespace internal { - static InterruptVerifierResult interrupt_verifier(); - static void interrupt_handler(uint32_t); + static SysCall::InterruptVerifierResult interrupt_verifier(); + static uint32_t interrupt_handler(uint32_t); static uint8_t vsync_counter = 0; - InterrupCallback callback = { + SysCall::InterrupCallback callback = { .next = nullptr, - .handler_function = reinterpret_cast(interrupt_handler), + .handler_function = interrupt_handler, .verifier_function = interrupt_verifier }; - static InterruptVerifierResult interrupt_verifier() { + static SysCall::InterruptVerifierResult interrupt_verifier() { if(Interrupt::is_irq(Interrupt::VBlank)) { - return InterruptVerifierResult::ExecuteHandler; + return SysCall::InterruptVerifierResult::ExecuteHandler; } else { - return InterruptVerifierResult::SkipHandler; + return SysCall::InterruptVerifierResult::SkipHandler; } } - static void interrupt_handler(uint32_t) { + static uint32_t interrupt_handler(uint32_t) { vsync_counter++; MasterTime::value++; Interrupt::ack_irq(Interrupt::VBlank); - __syscall_ReturnFromException(); + SysCall::ReturnFromException(); + __builtin_unreachable(); } uint32_t Display :: exchange_buffer_and_display() { diff --git a/src/Library/src/Timer/high_res_timer.cpp b/src/Library/src/Timer/high_res_timer.cpp index 45f5d650..71037176 100644 --- a/src/Library/src/Timer/high_res_timer.cpp +++ b/src/Library/src/Timer/high_res_timer.cpp @@ -1,6 +1,6 @@ #define private public #include -#include +#include #include #undef private @@ -8,26 +8,27 @@ namespace JabyEngine { volatile uint16_t HighResTime :: global_counter_10ms = 0; namespace Timer { - static InterruptVerifierResult interrupt_verifier() { + static SysCall::InterruptVerifierResult interrupt_verifier() { if(Interrupt::is_irq(Interrupt::Timer2)) { - return InterruptVerifierResult::ExecuteHandler; + return SysCall::InterruptVerifierResult::ExecuteHandler; } else { - return InterruptVerifierResult::SkipHandler; + return SysCall::InterruptVerifierResult::SkipHandler; } } - static void interrupt_handler(uint32_t) { + static uint32_t interrupt_handler(uint32_t) { HighResTime::global_counter_10ms = HighResTime::global_counter_10ms + 1; Interrupt::ack_irq(Interrupt::Timer2); - __syscall_ReturnFromException(); + SysCall::ReturnFromException(); + __builtin_unreachable(); } - InterrupCallback IRQCallback = { + SysCall::InterrupCallback IRQCallback = { .next = nullptr, - .handler_function = reinterpret_cast(interrupt_handler), + .handler_function = interrupt_handler, .verifier_function = interrupt_verifier }; } diff --git a/src/Library/src/syscall_printf.s b/src/Library/src/syscall_printf.s index eaf86b84..4324da91 100644 --- a/src/Library/src/syscall_printf.s +++ b/src/Library/src/syscall_printf.s @@ -2,10 +2,10 @@ .set noreorder .section .text, "ax", @progbits .align 2 - .global __syscall_printf - .type __syscall_printf, @function + .global _ZN10JabyEngine7SysCall6printfEPKcz + .type _ZN10JabyEngine7SysCall6printfEPKcz, @function -__syscall_printf: +_ZN10JabyEngine7SysCall6printfEPKcz: li $t2, 0xa0 jr $t2 li $t1, 0x3f