Use original code instead of frankensteining

This commit is contained in:
jaby 2024-05-13 21:46:42 +02:00
parent 6a68500896
commit c5cb59caa8
3 changed files with 45 additions and 122 deletions

View File

@ -54,24 +54,41 @@ namespace JabyEngine {
uint32_t lo; uint32_t lo;
uint32_t sr; uint32_t sr;
uint32_t cause; uint32_t cause;
uint32_t unused2[6]; uint32_t unused2[9];
}; };
struct PCB { struct PCB {
TCB* current_tcb; TCB* current_tcb;
}; };
static __always_inline TCB* get_tcb_of_th(uint32_t id) { struct ToT {
return reinterpret_cast<TCB*>((*reinterpret_cast<uint32_t*>(0x110)) + (id*4)); using ExCB = void;
} using EvCB = void;
using FCB = void;
static __always_inline void set_tcb(TCB* adr) { ExCB* exception_chain;
reinterpret_cast<PCB*>(0x108)->current_tcb = adr; 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() { extern ToT table_of_tables;
return *reinterpret_cast<PCB*>(0x108)->current_tcb;
}
namespace SysCall { namespace SysCall {
static constexpr const uint32_t Table_A = 0xA0; static constexpr const uint32_t Table_A = 0xA0;
@ -113,6 +130,12 @@ namespace JabyEngine {
#define __syscall_function_cast(table, ...) reinterpret_cast<__VA_ARGS__>(table) #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) { static __always_inline void* memcpy(void *dst, const void *src, size_t len) {
register uint32_t FuncID asm("t1") = 0x2A; register uint32_t FuncID asm("t1") = 0x2A;
__asm__ volatile("" : "=r"(FuncID) : "r"(FuncID)); __asm__ volatile("" : "=r"(FuncID) : "r"(FuncID));

View File

@ -31,10 +31,11 @@ ENTRY(_ZN10JabyEngine5startEv)
TLOAD_ADDR = DEFINED(TLOAD_ADDR) ? TLOAD_ADDR : 0x80010000; TLOAD_ADDR = DEFINED(TLOAD_ADDR) ? TLOAD_ADDR : 0x80010000;
MEMORY { MEMORY {
bios : ORIGIN = 0x100, LENGTH = 0x500
loader : ORIGIN = (TLOAD_ADDR - 0x800), LENGTH = 2048 loader : ORIGIN = (TLOAD_ADDR - 0x800), LENGTH = 2048
ram(rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 0x10000 ram(rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 0x10000
ram_alt(rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 0x10000 ram_alt(rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 0x10000
dcache : ORIGIN = 0x1f800000, LENGTH = 0x400 dcache : ORIGIN = 0x1f800000, LENGTH = 0x400
} }
__ram_top = ORIGIN(ram) + LENGTH(ram); __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); __stack_start = ORIGIN(ram) + LENGTH(ram);
SECTIONS { SECTIONS {
.bios (NOLOAD) : {
_ZN10JabyEngine15table_of_tablesE = .;
} > bios
/DISCARD/ : { *(.MIPS.abiflags) } /DISCARD/ : { *(.MIPS.abiflags) }
/* Everything is statically linked, so discard PLTs. */ /* Everything is statically linked, so discard PLTs. */

View File

@ -3,95 +3,8 @@
#include <PSX/System/IOPorts/interrupt_io.hpp> #include <PSX/System/IOPorts/interrupt_io.hpp>
#include <PSX/System/syscalls.hpp> #include <PSX/System/syscalls.hpp>
#include <stdio.hpp> #include <stdio.hpp>
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 { 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 CD {
namespace internal { namespace internal {
static constexpr auto AudioSectorMode = CD_IO::Mode::from(CD_IO::Mode::SingleSpeed, CD_IO::Mode::AutoPauseTrack, CD_IO::Mode::CDDA); 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) { if(thread != 0) {
//changeThread(thread); //changeThread(thread);
printf("About to change...\n"); printf("About to change...\n");
exec_TCB->entry = reinterpret_cast<TCB*>(&__globals->threads[thread & 0xffff]); table_of_tables.processes->current_tcb = &table_of_tables.threads[thread&0xFFFF];
printf("Changed!\n"); printf("Changed!\n");
} }
} break; } break;
@ -226,8 +139,6 @@ int changeThread(int threadId) { return SysCall::changeThreadSubFunction((uint32
// 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);
Interrupt::ack_irq(Interrupt::CDROM); Interrupt::ack_irq(Interrupt::CDROM);
Interrupt::enable_irq(Interrupt::CDROM);
printf("RET-E\n");
SysCall::ReturnFromException(); SysCall::ReturnFromException();
__builtin_unreachable(); __builtin_unreachable();
} }
@ -253,35 +164,18 @@ int changeThread(int threadId) { return SysCall::changeThreadSubFunction((uint32
void enable_CDDA() { void enable_CDDA() {
if(thread == 0) { if(thread == 0) {
__globals = reinterpret_cast<Globals*>(0x100);
ToT *table = (ToT*)0x100;
exec_TCB = (TCBH*)table[1].head;
mainFlow = exec_TCB->entry;
SysCall::EnterCriticalSection(); SysCall::EnterCriticalSection();
thread = SysCall::OpenTh([]() { thread = SysCall::OpenTh([]() {
printf("Hallo!\n"); 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(); CD_IO::PortIndex0::change_to();
printf("Schwupp!\n");
Command::send<CD_IO::PortIndex0>(CD_IO::Command::SetLoc, static_cast<uint8_t>(0x0), static_cast<uint8_t>(0x09), static_cast<uint8_t>(0x0)); Command::send<CD_IO::PortIndex0>(CD_IO::Command::SetLoc, static_cast<uint8_t>(0x0), static_cast<uint8_t>(0x09), static_cast<uint8_t>(0x0));
printf("Mupp\n");
Command::send<CD_IO::PortIndex0>(CD_IO::Command::Play); Command::send<CD_IO::PortIndex0>(CD_IO::Command::Play);
printf("Done!!\n");
exec_TCB->entry = mainFlow; table_of_tables.processes->current_tcb = &table_of_tables.threads[0];
SysCall::ReturnFromException(); SysCall::ReturnFromException();
//changeThread(0); }, reinterpret_cast<uint32_t*>(0x80010000), SysCall::get_gp());
}, reinterpret_cast<uint32_t*>(0x80010000), reinterpret_cast<uint32_t*>(mainFlow->reg[28]));
SysCall::ExitCriticalSection(); 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(); Command::wait_completed();