mirror of
https://github.com/ran-j/PS2Recomp.git
synced 2026-10-08 20:21:02 -04:00
feat: added runtime base stubs definitions
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <functional>
|
||||
#include <immintrin.h> // For SSE/AVX instructions
|
||||
|
||||
constexpr uint32_t PS2_RAM_MASK = 0xF0000000;
|
||||
constexpr uint32_t PS2_RAM_BASE = 0x00000000;
|
||||
constexpr uint32_t PS2_RAM_SIZE = 32 * 1024 * 1024; // 32MB
|
||||
constexpr uint32_t PS2_SCRATCHPAD_BASE = 0x70000000;
|
||||
@@ -131,8 +132,40 @@ struct R5900Context
|
||||
// Reset COP1 state
|
||||
fcr31 = 0;
|
||||
}
|
||||
|
||||
~R5900Context() = default;
|
||||
};
|
||||
|
||||
inline uint32_t getRegU32(const R5900Context *ctx, int reg)
|
||||
{
|
||||
// Check if reg is valid (0-31)
|
||||
if (reg < 0 || reg > 31)
|
||||
return 0;
|
||||
return ctx->r[reg].m128i_u32[0];
|
||||
}
|
||||
|
||||
inline void setReturnU32(R5900Context *ctx, uint32_t value)
|
||||
{
|
||||
ctx->r[2] = _mm_set_epi32(0, 0, 0, value); // $v0
|
||||
}
|
||||
|
||||
inline void setReturnS32(R5900Context *ctx, int32_t value)
|
||||
{
|
||||
ctx->r[2] = _mm_set_epi32(0, 0, 0, value); // $v0 Sign extension handled by cast? TODO Check MIPS ABI.
|
||||
}
|
||||
|
||||
inline uint8_t *getMemPtr(uint8_t *rdram, uint32_t addr)
|
||||
{
|
||||
constexpr uint32_t PS2_RAM_MASK = PS2_RAM_SIZE - 1;
|
||||
return rdram + (addr & PS2_RAM_MASK);
|
||||
}
|
||||
|
||||
inline const uint8_t *getConstMemPtr(uint8_t *rdram, uint32_t addr)
|
||||
{
|
||||
constexpr uint32_t PS2_RAM_MASK = PS2_RAM_SIZE - 1;
|
||||
return rdram + (addr & PS2_RAM_MASK);
|
||||
}
|
||||
|
||||
// PS2 GS (Graphics Synthesizer) registers
|
||||
struct GSRegisters
|
||||
{
|
||||
@@ -299,10 +332,8 @@ private:
|
||||
PS2Memory m_memory;
|
||||
R5900Context m_cpuContext;
|
||||
|
||||
// Function table for recompiled code
|
||||
std::unordered_map<uint32_t, RecompiledFunction> m_functionTable;
|
||||
|
||||
// Currently loaded modules
|
||||
struct LoadedModule
|
||||
{
|
||||
std::string name;
|
||||
|
||||
@@ -2,11 +2,16 @@
|
||||
#define PS2_STUBS_H
|
||||
|
||||
#include "ps2_runtime.h"
|
||||
#include <cstdint>
|
||||
|
||||
// Standard library implementation stubs
|
||||
namespace ps2_stubs
|
||||
{
|
||||
|
||||
// Memory operations
|
||||
void malloc(uint8_t *rdram, R5900Context *ctx);
|
||||
void free(uint8_t *rdram, R5900Context *ctx);
|
||||
void calloc(uint8_t *rdram, R5900Context *ctx);
|
||||
void realloc(uint8_t *rdram, R5900Context *ctx);
|
||||
void memcpy(uint8_t *rdram, R5900Context *ctx);
|
||||
void memset(uint8_t *rdram, R5900Context *ctx);
|
||||
void memmove(uint8_t *rdram, R5900Context *ctx);
|
||||
@@ -18,87 +23,41 @@ namespace ps2_stubs
|
||||
void strlen(uint8_t *rdram, R5900Context *ctx);
|
||||
void strcmp(uint8_t *rdram, R5900Context *ctx);
|
||||
void strncmp(uint8_t *rdram, R5900Context *ctx);
|
||||
void strcat(uint8_t *rdram, R5900Context *ctx);
|
||||
void strncat(uint8_t *rdram, R5900Context *ctx);
|
||||
void strchr(uint8_t *rdram, R5900Context *ctx);
|
||||
void strrchr(uint8_t *rdram, R5900Context *ctx);
|
||||
void strstr(uint8_t *rdram, R5900Context *ctx);
|
||||
|
||||
// I/O operations
|
||||
void printf(uint8_t *rdram, R5900Context *ctx);
|
||||
void sprintf(uint8_t *rdram, R5900Context *ctx);
|
||||
void snprintf(uint8_t *rdram, R5900Context *ctx);
|
||||
void puts(uint8_t *rdram, R5900Context *ctx);
|
||||
|
||||
// Memory allocation
|
||||
void malloc(uint8_t *rdram, R5900Context *ctx);
|
||||
void free(uint8_t *rdram, R5900Context *ctx);
|
||||
void calloc(uint8_t *rdram, R5900Context *ctx);
|
||||
void realloc(uint8_t *rdram, R5900Context *ctx);
|
||||
void fopen(uint8_t *rdram, R5900Context *ctx);
|
||||
void fclose(uint8_t *rdram, R5900Context *ctx);
|
||||
void fread(uint8_t *rdram, R5900Context *ctx);
|
||||
void fwrite(uint8_t *rdram, R5900Context *ctx);
|
||||
void fprintf(uint8_t *rdram, R5900Context *ctx);
|
||||
void fseek(uint8_t *rdram, R5900Context *ctx);
|
||||
void ftell(uint8_t *rdram, R5900Context *ctx);
|
||||
void fflush(uint8_t *rdram, R5900Context *ctx);
|
||||
|
||||
// Math functions
|
||||
void sqrt(uint8_t *rdram, R5900Context *ctx);
|
||||
void sin(uint8_t *rdram, R5900Context *ctx);
|
||||
void cos(uint8_t *rdram, R5900Context *ctx);
|
||||
void tan(uint8_t *rdram, R5900Context *ctx);
|
||||
void atan2(uint8_t *rdram, R5900Context *ctx);
|
||||
void pow(uint8_t *rdram, R5900Context *ctx);
|
||||
void exp(uint8_t *rdram, R5900Context *ctx);
|
||||
void log(uint8_t *rdram, R5900Context *ctx);
|
||||
void log10(uint8_t *rdram, R5900Context *ctx);
|
||||
void ceil(uint8_t *rdram, R5900Context *ctx);
|
||||
void floor(uint8_t *rdram, R5900Context *ctx);
|
||||
void fabs(uint8_t *rdram, R5900Context *ctx);
|
||||
|
||||
void TODO(uint8_t *rdram, R5900Context *ctx);
|
||||
}
|
||||
|
||||
// PS2 system call implementation stubs
|
||||
namespace ps2_syscalls
|
||||
{
|
||||
void FlushCache(uint8_t *rdram, R5900Context *ctx);
|
||||
void ExitThread(uint8_t *rdram, R5900Context *ctx);
|
||||
void SleepThread(uint8_t *rdram, R5900Context *ctx);
|
||||
void CreateThread(uint8_t *rdram, R5900Context *ctx);
|
||||
void StartThread(uint8_t *rdram, R5900Context *ctx);
|
||||
void SifInitRpc(uint8_t *rdram, R5900Context *ctx);
|
||||
void SifBindRpc(uint8_t *rdram, R5900Context *ctx);
|
||||
void SifCallRpc(uint8_t *rdram, R5900Context *ctx);
|
||||
void SetGsCrt(uint8_t *rdram, R5900Context *ctx);
|
||||
}
|
||||
|
||||
// MMI operation implementations
|
||||
namespace ps2_mmi
|
||||
{
|
||||
void PADDW(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PSUBW(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PCGTW(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PMAXW(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PADDH(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PSUBH(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PCGTH(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PMAXH(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PADDB(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PSUBB(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PCGTB(R5900Context *ctx, int rd, int rs, int rt);
|
||||
|
||||
void PEXTLW(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PEXTUW(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PEXTLH(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PEXTUH(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PEXTLB(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PEXTUB(R5900Context *ctx, int rd, int rs, int rt);
|
||||
|
||||
void PMADDW(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PMSUBW(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PMADDH(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PMSUBH(R5900Context *ctx, int rd, int rs, int rt);
|
||||
|
||||
void PAND(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void POR(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PXOR(R5900Context *ctx, int rd, int rs, int rt);
|
||||
void PNOR(R5900Context *ctx, int rd, int rs, int rt);
|
||||
}
|
||||
|
||||
// Hardware register handlers
|
||||
namespace ps2_hardware
|
||||
{
|
||||
// DMA channel handlers
|
||||
void handleDmacReg(uint32_t address, uint32_t value);
|
||||
|
||||
// GS register handlers
|
||||
void handleGsReg(uint32_t address, uint32_t value);
|
||||
|
||||
// VIF register handlers
|
||||
void handleVif0Reg(uint32_t address, uint32_t value);
|
||||
void handleVif1Reg(uint32_t address, uint32_t value);
|
||||
|
||||
void handleTimerReg(uint32_t address, uint32_t value);
|
||||
void handleSPU2Reg(uint32_t address, uint32_t value);
|
||||
}
|
||||
|
||||
#endif // PS2_RUNTIME_H
|
||||
#endif // PS2_STUBS_H
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
#ifndef PS2_SYSCALLS_H
|
||||
#define PS2_SYSCALLS_H
|
||||
|
||||
#include "ps2_runtime.h"
|
||||
|
||||
#define PS2_FIO_O_RDONLY 0x0001
|
||||
#define PS2_FIO_O_WRONLY 0x0002
|
||||
#define PS2_FIO_O_RDWR 0x0003
|
||||
#define PS2_FIO_O_NBLOCK 0x0010
|
||||
#define PS2_FIO_O_APPEND 0x0100
|
||||
#define PS2_FIO_O_CREAT 0x0200
|
||||
#define PS2_FIO_O_TRUNC 0x0400
|
||||
#define PS2_FIO_O_EXCL 0x0800
|
||||
#define PS2_FIO_O_NOWAIT 0x8000
|
||||
|
||||
#define PS2_SEEK_SET 0
|
||||
#define PS2_SEEK_CUR 1
|
||||
#define PS2_SEEK_END 2
|
||||
|
||||
namespace ps2_syscalls
|
||||
{
|
||||
void FlushCache(uint8_t *rdram, R5900Context *ctx);
|
||||
void ResetEE(uint8_t *rdram, R5900Context *ctx);
|
||||
void SetMemoryMode(uint8_t *rdram, R5900Context *ctx);
|
||||
|
||||
void CreateThread(uint8_t *rdram, R5900Context *ctx);
|
||||
void DeleteThread(uint8_t *rdram, R5900Context *ctx);
|
||||
void StartThread(uint8_t *rdram, R5900Context *ctx);
|
||||
void ExitThread(uint8_t *rdram, R5900Context *ctx);
|
||||
void ExitDeleteThread(uint8_t *rdram, R5900Context *ctx);
|
||||
void TerminateThread(uint8_t *rdram, R5900Context *ctx);
|
||||
void SuspendThread(uint8_t *rdram, R5900Context *ctx);
|
||||
void ResumeThread(uint8_t *rdram, R5900Context *ctx);
|
||||
void GetThreadId(uint8_t *rdram, R5900Context *ctx);
|
||||
void ReferThreadStatus(uint8_t *rdram, R5900Context *ctx);
|
||||
void SleepThread(uint8_t *rdram, R5900Context *ctx);
|
||||
void WakeupThread(uint8_t *rdram, R5900Context *ctx);
|
||||
void iWakeupThread(uint8_t *rdram, R5900Context *ctx);
|
||||
void ChangeThreadPriority(uint8_t *rdram, R5900Context *ctx);
|
||||
void RotateThreadReadyQueue(uint8_t *rdram, R5900Context *ctx);
|
||||
void ReleaseWaitThread(uint8_t *rdram, R5900Context *ctx);
|
||||
void iReleaseWaitThread(uint8_t *rdram, R5900Context *ctx);
|
||||
|
||||
void CreateSema(uint8_t *rdram, R5900Context *ctx);
|
||||
void DeleteSema(uint8_t *rdram, R5900Context *ctx);
|
||||
void SignalSema(uint8_t *rdram, R5900Context *ctx);
|
||||
void iSignalSema(uint8_t *rdram, R5900Context *ctx);
|
||||
void WaitSema(uint8_t *rdram, R5900Context *ctx);
|
||||
void PollSema(uint8_t *rdram, R5900Context *ctx);
|
||||
void iPollSema(uint8_t *rdram, R5900Context *ctx);
|
||||
void ReferSemaStatus(uint8_t *rdram, R5900Context *ctx);
|
||||
void iReferSemaStatus(uint8_t *rdram, R5900Context *ctx);
|
||||
|
||||
void CreateEventFlag(uint8_t *rdram, R5900Context *ctx);
|
||||
void DeleteEventFlag(uint8_t *rdram, R5900Context *ctx);
|
||||
void SetEventFlag(uint8_t *rdram, R5900Context *ctx);
|
||||
void iSetEventFlag(uint8_t *rdram, R5900Context *ctx);
|
||||
void ClearEventFlag(uint8_t *rdram, R5900Context *ctx);
|
||||
void iClearEventFlag(uint8_t *rdram, R5900Context *ctx);
|
||||
void WaitEventFlag(uint8_t *rdram, R5900Context *ctx);
|
||||
void PollEventFlag(uint8_t *rdram, R5900Context *ctx);
|
||||
void iPollEventFlag(uint8_t *rdram, R5900Context *ctx);
|
||||
void ReferEventFlagStatus(uint8_t *rdram, R5900Context *ctx);
|
||||
void iReferEventFlagStatus(uint8_t *rdram, R5900Context *ctx);
|
||||
|
||||
void SetAlarm(uint8_t *rdram, R5900Context *ctx);
|
||||
void iSetAlarm(uint8_t *rdram, R5900Context *ctx);
|
||||
void CancelAlarm(uint8_t *rdram, R5900Context *ctx);
|
||||
void iCancelAlarm(uint8_t *rdram, R5900Context *ctx);
|
||||
|
||||
void EnableIntc(uint8_t *rdram, R5900Context *ctx);
|
||||
void DisableIntc(uint8_t *rdram, R5900Context *ctx);
|
||||
void EnableDmac(uint8_t *rdram, R5900Context *ctx);
|
||||
void DisableDmac(uint8_t *rdram, R5900Context *ctx);
|
||||
|
||||
void SifStopModule(uint8_t *rdram, R5900Context *ctx);
|
||||
void SifLoadModule(uint8_t *rdram, R5900Context *ctx);
|
||||
void SifInitRpc(uint8_t *rdram, R5900Context *ctx);
|
||||
void SifBindRpc(uint8_t *rdram, R5900Context *ctx);
|
||||
void SifCallRpc(uint8_t *rdram, R5900Context *ctx);
|
||||
void SifRegisterRpc(uint8_t *rdram, R5900Context *ctx);
|
||||
void SifCheckStatRpc(uint8_t *rdram, R5900Context *ctx);
|
||||
void SifSetRpcQueue(uint8_t *rdram, R5900Context *ctx);
|
||||
void SifRemoveRpcQueue(uint8_t *rdram, R5900Context *ctx);
|
||||
void SifRemoveRpc(uint8_t *rdram, R5900Context *ctx);
|
||||
|
||||
void fioOpen(uint8_t *rdram, R5900Context *ctx);
|
||||
void fioClose(uint8_t *rdram, R5900Context *ctx);
|
||||
void fioRead(uint8_t *rdram, R5900Context *ctx);
|
||||
void fioWrite(uint8_t *rdram, R5900Context *ctx);
|
||||
void fioLseek(uint8_t *rdram, R5900Context *ctx);
|
||||
void fioMkdir(uint8_t *rdram, R5900Context *ctx);
|
||||
void fioChdir(uint8_t *rdram, R5900Context *ctx);
|
||||
void fioRmdir(uint8_t *rdram, R5900Context *ctx);
|
||||
void fioGetstat(uint8_t *rdram, R5900Context *ctx);
|
||||
void fioRemove(uint8_t *rdram, R5900Context *ctx);
|
||||
|
||||
void GsSetCrt(uint8_t *rdram, R5900Context *ctx);
|
||||
void GsGetIMR(uint8_t *rdram, R5900Context *ctx);
|
||||
void GsPutIMR(uint8_t *rdram, R5900Context *ctx);
|
||||
void GsSetVideoMode(uint8_t *rdram, R5900Context *ctx);
|
||||
|
||||
void GetOsdConfigParam(uint8_t *rdram, R5900Context *ctx);
|
||||
void SetOsdConfigParam(uint8_t *rdram, R5900Context *ctx);
|
||||
void GetRomName(uint8_t *rdram, R5900Context *ctx);
|
||||
void SifLoadElfPart(uint8_t *rdram, R5900Context *ctx);
|
||||
void sceSifLoadModule(uint8_t *rdram, R5900Context *ctx);
|
||||
|
||||
void TODO(uint8_t *rdram, R5900Context *ctx);
|
||||
|
||||
// Helper functions
|
||||
void RenderFrame(uint8_t *rdram);
|
||||
}
|
||||
|
||||
#endif // PS2_SYSCALLS_H
|
||||
Reference in New Issue
Block a user