diff --git a/include/PSX/System/syscalls.hpp b/include/PSX/System/syscalls.hpp index 987b948b..6dd5d74e 100644 --- a/include/PSX/System/syscalls.hpp +++ b/include/PSX/System/syscalls.hpp @@ -54,24 +54,41 @@ namespace JabyEngine { uint32_t lo; uint32_t sr; uint32_t cause; - uint32_t unused2[6]; + uint32_t unused2[9]; }; struct PCB { TCB* current_tcb; }; - static __always_inline TCB* get_tcb_of_th(uint32_t id) { - return reinterpret_cast((*reinterpret_cast(0x110)) + (id*4)); - } + struct ToT { + using ExCB = void; + using EvCB = void; + using FCB = void; - static __always_inline void set_tcb(TCB* adr) { - reinterpret_cast(0x108)->current_tcb = adr; - } + ExCB* exception_chain; + uint32_t exception_chain_size; + PCB* processes; + uint32_t processes_size; + TCB* threads; + uint32_t threads_size; + uint32_t reserved_0; + uint32_t reserved_1; + EvCB* events; + uint32_t events_size; + uint32_t reserved_2; + uint32_t reserved_3; + uint32_t reserved_4; + uint32_t reserved_5; + uint32_t reserved_6; + uint32_t reserved_7; + FCB* files; + uint32_t files_size; + uint32_t reserved_8; + uint32_t reserved_9; + }; - static __always_inline TCB& get_current_tcb() { - return *reinterpret_cast(0x108)->current_tcb; - } + extern ToT table_of_tables; namespace SysCall { static constexpr const uint32_t Table_A = 0xA0; @@ -113,6 +130,12 @@ namespace JabyEngine { #define __syscall_function_cast(table, ...) reinterpret_cast<__VA_ARGS__>(table) + static __always_inline uint32_t* get_gp() { + uint32_t* gp; + __asm__("sw $gp, %0" : "=m"(gp)); + return gp; + } + 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)); diff --git a/mkfile/psexe.ld b/mkfile/psexe.ld index cde05fcb..d1fef6ec 100644 --- a/mkfile/psexe.ld +++ b/mkfile/psexe.ld @@ -31,10 +31,11 @@ ENTRY(_ZN10JabyEngine5startEv) TLOAD_ADDR = DEFINED(TLOAD_ADDR) ? TLOAD_ADDR : 0x80010000; MEMORY { + bios : ORIGIN = 0x100, LENGTH = 0x500 loader : ORIGIN = (TLOAD_ADDR - 0x800), LENGTH = 2048 - ram(rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 0x10000 - ram_alt(rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 0x10000 - dcache : ORIGIN = 0x1f800000, LENGTH = 0x400 + ram(rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 0x10000 + ram_alt(rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 0x10000 + dcache : ORIGIN = 0x1f800000, LENGTH = 0x400 } __ram_top = ORIGIN(ram) + LENGTH(ram); @@ -50,7 +51,12 @@ __persistent_lbas_len = (__persistent_lbas_end - __persistent_lbas_start); __stack_start = ORIGIN(ram) + LENGTH(ram); + SECTIONS { + .bios (NOLOAD) : { + _ZN10JabyEngine15table_of_tablesE = .; + } > bios + /DISCARD/ : { *(.MIPS.abiflags) } /* Everything is statically linked, so discard PLTs. */ diff --git a/src/Library/src/CD/cd.cpp b/src/Library/src/CD/cd.cpp index 6d7792b0..7d557d51 100644 --- a/src/Library/src/CD/cd.cpp +++ b/src/Library/src/CD/cd.cpp @@ -3,95 +3,8 @@ #include #include #include -struct Registers { - union { - struct { - uint32_t r0, at, v0, v1, a0, a1, a2, a3; - uint32_t t0, t1, t2, t3, t4, t5, t6, t7; - uint32_t s0, s1, s2, s3, s4, s5, s6, s7; - uint32_t t8, t9, k0, k1, gp, sp, fp, ra; - } n; - uint32_t r[32]; - } GPR; - uint32_t returnPC; - uint32_t hi, lo; - uint32_t SR; - uint32_t Cause; -}; - -struct Thread { - uint32_t flags, flags2; - struct Registers registers; - uint32_t unknown[9]; -}; - -struct Process { - struct Thread* thread; -}; - -struct Globals { - /* 100 */ struct HandlersStorage* handlersArray; - /* 104 */ uint32_t handlersArraySize; - /* 108 */ struct Process* processes; - /* 10c */ uint32_t processBlockSize; - /* 110 */ struct Thread* threads; - /* 114 */ uint32_t threadBlockSize; - /* 118 */ uint32_t xxx_06; - /* 11c */ uint32_t xxx_07; - /* 120 */ struct EventInfo* events; - /* 124 */ uint32_t eventsSize; - /* 128 */ uint32_t xxx_0a; - /* 12c */ uint32_t xxx_0b; - /* 130 */ uint32_t xxx_0c; - /* 134 */ uint32_t xxx_0d; - /* 138 */ uint32_t xxx_0e; - /* 13c */ uint32_t xxx_0f; - /* 140 */ struct File* files; - /* 144 */ uint32_t filesSize; - /* 148 */ uint32_t xxx_12; - /* 14c */ uint32_t xxx_13; - /* 150 */ struct Device* devices; - /* 154 */ struct Device* devicesEnd; - /* 158 */ uint32_t xxx_16; - /* 15c */ uint32_t xxx_17; - /* 160 */ uint32_t xxx_18; - /* 164 */ uint32_t xxx_19; - /* 168 */ uint32_t xxx_1a; - /* 16c */ uint32_t xxx_1b; - /* 170 */ uint32_t xxx_1c; - /* 174 */ uint32_t xxx_1d; - /* 178 */ uint32_t xxx_1e; - /* 17c */ uint32_t xxx_1f; -}; - -Globals *__globals; namespace JabyEngine { - struct ToT { - unsigned long *head; - long size; -}; - -struct TCBH { - TCB *entry; /* NULL */ - long flag; -}; - -TCBH *exec_TCB; -TCB *mainFlow; - -inline unsigned short getSystemTableNumber(uint32_t thread) -{ - return (thread & 0xFFFF); -} - -inline TCB* getTCB(uint32_t thread) -{ - return (TCB*) (((ToT*)0x100)[2]).head + getSystemTableNumber(thread); -} - -int changeThread(int threadId) { return SysCall::changeThreadSubFunction((uint32_t)&__globals->threads[threadId & 0xffff]); } - namespace CD { namespace internal { static constexpr auto AudioSectorMode = CD_IO::Mode::from(CD_IO::Mode::SingleSpeed, CD_IO::Mode::AutoPauseTrack, CD_IO::Mode::CDDA); @@ -213,7 +126,7 @@ int changeThread(int threadId) { return SysCall::changeThreadSubFunction((uint32 if(thread != 0) { //changeThread(thread); printf("About to change...\n"); - exec_TCB->entry = reinterpret_cast(&__globals->threads[thread & 0xffff]); + table_of_tables.processes->current_tcb = &table_of_tables.threads[thread&0xFFFF]; printf("Changed!\n"); } } break; @@ -226,8 +139,6 @@ int changeThread(int threadId) { return SysCall::changeThreadSubFunction((uint32 // No masking required because we can only write bit 0 - 2 CD_IO::IndexStatus.write(old_status); Interrupt::ack_irq(Interrupt::CDROM); - Interrupt::enable_irq(Interrupt::CDROM); - printf("RET-E\n"); SysCall::ReturnFromException(); __builtin_unreachable(); } @@ -253,35 +164,18 @@ int changeThread(int threadId) { return SysCall::changeThreadSubFunction((uint32 void enable_CDDA() { if(thread == 0) { - __globals = reinterpret_cast(0x100); - ToT *table = (ToT*)0x100; - exec_TCB = (TCBH*)table[1].head; - mainFlow = exec_TCB->entry; - SysCall::EnterCriticalSection(); thread = SysCall::OpenTh([]() { printf("Hallo!\n"); - printf("Me: 0x%p - 0x%p\n", get_tcb_of_th(thread), &get_current_tcb()); - printf("Blubb!\n"); CD_IO::PortIndex0::change_to(); - printf("Schwupp!\n"); Command::send(CD_IO::Command::SetLoc, static_cast(0x0), static_cast(0x09), static_cast(0x0)); - printf("Mupp\n"); Command::send(CD_IO::Command::Play); - printf("Done!!\n"); - exec_TCB->entry = mainFlow; + table_of_tables.processes->current_tcb = &table_of_tables.threads[0]; SysCall::ReturnFromException(); - //changeThread(0); - }, reinterpret_cast(0x80010000), reinterpret_cast(mainFlow->reg[28])); + }, reinterpret_cast(0x80010000), SysCall::get_gp()); SysCall::ExitCriticalSection(); - - printf("Raw: %x, TCB: %i\n", thread, thread & 0xFFFF); - //__globals->threads[thread & 0xffff].registers.SR = 0x404; - - //mainFlow = exec_TCB->entry; - //changeThread(thread); } Command::wait_completed();