Import gx, PadClamp, rest of mtx, TRK 2.6 and MSL (#525)

* Match mtx and Padclamp.c

* Match the rest of GX

* Import TRK 2.6

* Import MSL headers and files

* Merge some MSL headers into ours
This commit is contained in:
dbalatoni13 2025-01-12 15:11:23 +01:00 committed by GitHub
parent a79294aac0
commit cdb1d1fc37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
113 changed files with 11219 additions and 394 deletions

View file

@ -0,0 +1,35 @@
#ifndef METROTRK_PORTABLE_DISPATCH_H
#define METROTRK_PORTABLE_DISPATCH_H
#include "dolphin/types.h"
#include "PowerPC_EABI_Support/MetroTRK/trk.h"
#ifdef __cplusplus
extern "C" {
#endif
#define TRK_DISPATCH_CMD_CONNECT 1 /* Connect to the console */
#define TRK_DISPATCH_CMD_DISCONNECT 2 /* Disconnect from the console */
#define TRK_DISPATCH_CMD_RESET 3 /* Reset the debugger */
#define TRK_DISPATCH_CMD_GETVERSION 4 /* Get debugger version */
#define TRK_DISPATCH_CMD_GETSUPPORTMASK 5 /* Get Support Mask */
#define TRK_DISPATCH_CMD_OVERRIDE 7 /* Override? */
#define TRK_DISPATCH_CMD_READMEM 16 /* Reading from memory */
#define TRK_DISPATCH_CMD_WRITEMEM 17 /* Writing to memory */
#define TRK_DISPATCH_CMD_READREGS 18 /* Read a register value */
#define TRK_DISPATCH_CMD_WRITEREGS 19 /* Set a register */
#define TRK_DISPATCH_CMD_SETOPTION 23 /* Set an option? */
#define TRK_DISPATCH_CMD_CONTINUE 24 /* Continue debugging */
#define TRK_DISPATCH_CMD_STEP 25 /* Step through an instruction */
#define TRK_DISPATCH_CMD_STOP 26 /* Stop the debugger */
typedef struct TRKBuffer TRKBuffer;
DSError TRKInitializeDispatcher();
BOOL TRKDispatchMessage(TRKBuffer* buffer);
#ifdef __cplusplus
}
#endif
#endif /* METROTRK_PORTABLE_DISPATCH_H */

View file

@ -0,0 +1,16 @@
#ifndef METROTRK_PORTABLE_MAIN_TRK_H
#define METROTRK_PORTABLE_MAIN_TRK_H
#include "PowerPC_EABI_Support/MetroTRK/trk.h"
#ifdef __cplusplus
extern "C" {
#endif
DSError TRK_main(void);
#ifdef __cplusplus
}
#endif
#endif /* METROTRK_PORTABLE_MAIN_TRK_H */

View file

@ -0,0 +1,14 @@
#ifndef METROTRK_PORTABLE_MAINLOOP_H
#define METROTRK_PORTABLE_MAINLOOP_H
#ifdef __cplusplus
extern "C" {
#endif
void TRKNubMainLoop(void);
#ifdef __cplusplus
}
#endif
#endif /* METROTRK_PORTABLE_MAINLOOP_H */

View file

@ -0,0 +1,17 @@
#ifndef METROTRK_PORTABLE_MEM_TRK_H
#define METROTRK_PORTABLE_MEM_TRK_H
#include "stddef.h"
#ifdef __cplusplus
extern "C" {
#endif
void* TRK_memset(void* dst, int val, size_t n);
void* TRK_memcpy(void* dst, const void* src, size_t n);
#ifdef __cplusplus
}
#endif
#endif /* METROTRK_PORTABLE_MEM_TRK_H */

View file

@ -0,0 +1,24 @@
#ifndef METROTRK_PORTABLE_MSG_H
#define METROTRK_PORTABLE_MSG_H
#include "PowerPC_EABI_Support/MetroTRK/trk.h"
#include "dolphin/types.h"
typedef struct _TRK_Msg {
u8 _00[8];
u32 m_msgLength;
u32 _0C;
u32 m_msg;
} TRK_Msg;
#ifdef __cplusplus
extern "C" {
#endif
DSError TRKMessageSend(TRK_Msg* msg);
#ifdef __cplusplus
}
#endif
#endif /* METROTRK_PORTABLE_MSG_H */

View file

@ -0,0 +1,50 @@
#ifndef METROTRK_PORTABLE_MSGBUF_H
#define METROTRK_PORTABLE_MSGBUF_H
#include "PowerPC_EABI_Support/MetroTRK/trk.h"
#include "stddef.h"
#ifdef __cplusplus
extern "C" {
#endif
DSError TRKInitializeMessageBuffers(void);
DSError TRKSetBufferPosition(TRKBuffer* msg, u32 pos);
void* TRKGetBuffer(int);
void TRKResetBuffer(TRKBuffer* msg, BOOL keepData);
void* TRKGetBuffer(int idx);
void TRKReleaseBuffer(int idx);
DSError TRKGetFreeBuffer(int* msgID, TRKBuffer** outMsg);
DSError TRKAppendBuffer(TRKBuffer* msg, const void* data, size_t length);
DSError TRKAppendBuffer1_ui8(TRKBuffer* buffer, const u8 data);
inline DSError TRKAppendBuffer1_ui8(TRKBuffer* buffer, const u8 data)
{
if (buffer->position >= TRKMSGBUF_SIZE) {
return DS_MessageBufferOverflow;
}
buffer->data[buffer->position++] = data;
buffer->length++;
return DS_NoError;
}
DSError TRKAppendBuffer1_ui16(TRKBuffer* buffer, const u16 data);
DSError TRKAppendBuffer1_ui32(TRKBuffer* buffer, const u32 data);
DSError TRKAppendBuffer1_ui64(TRKBuffer* buffer, const u64 data);
DSError TRKAppendBuffer_ui8(TRKBuffer* buffer, const u8* data, int count);
DSError TRKAppendBuffer_ui32(TRKBuffer* buffer, const u32* data, int count);
DSError TRKReadBuffer1_ui8(TRKBuffer* buffer, u8* data);
DSError TRKReadBuffer1_ui16(TRKBuffer* buffer, u16* data);
DSError TRKReadBuffer1_ui32(TRKBuffer* buffer, u32* data);
DSError TRKReadBuffer1_ui64(TRKBuffer* buffer, u64* data);
DSError TRKReadBuffer_ui8(TRKBuffer* buffer, u8* data, int count);
DSError TRKReadBuffer_ui32(TRKBuffer* buffer, u32* data, int count);
DSError TRKReadBuffer(TRKBuffer* msg, void* data, size_t length);
#ifdef __cplusplus
}
#endif
#endif /* METROTRK_PORTABLE_MSGBUF_H */

View file

@ -0,0 +1,31 @@
#ifndef METROTRK_PORTABLE_MSGHNDLR_H
#define METROTRK_PORTABLE_MSGHNDLR_H
#include "PowerPC_EABI_Support/MetroTRK/trk.h"
void SetTRKConnected(BOOL);
BOOL GetTRKConnected(void);
DSError TRKDoUnsupported(TRKBuffer*);
DSError TRKDoSetOption(TRKBuffer*);
DSError TRKDoStop(TRKBuffer*);
DSError TRKDoStep(TRKBuffer*);
DSError TRKDoContinue(TRKBuffer*);
DSError TRKDoWriteRegisters(TRKBuffer*);
DSError TRKDoReadRegisters(TRKBuffer*);
DSError TRKDoFlushCache(TRKBuffer*);
DSError TRKDoWriteMemory(TRKBuffer*);
DSError TRKDoReadMemory(TRKBuffer*);
DSError TRKDoSupportMask(TRKBuffer*);
DSError TRKDoVersions(TRKBuffer*);
DSError TRKDoSupportMask(TRKBuffer*);
DSError TRKDoCPUType(TRKBuffer*);
DSError TRKDoOverride(TRKBuffer*);
DSError TRKDoReset(TRKBuffer*);
DSError TRKDoDisconnect(TRKBuffer*);
DSError TRKDoConnect(TRKBuffer*);
DSError TRKStandardACK(TRKBuffer* buffer, MessageCommandID commandID,
DSReplyError replyError);
void OutputData(void* data, int length);
#endif /* METROTRK_PORTABLE_MSGHNDLR_H */

View file

@ -0,0 +1,10 @@
#ifndef METROTRK_PORTABLE_MUTEX_TRK_H
#define METROTRK_PORTABLE_MUTEX_TRK_H
#include "PowerPC_EABI_Support/MetroTRK/trk.h"
DSError TRKInitializeMutex(void*);
DSError TRKAcquireMutex(void*);
DSError TRKReleaseMutex(void*);
#endif /* METROTRK_PORTABLE_MUTEX_TRK_H */

View file

@ -0,0 +1,16 @@
#ifndef METROTRK_PORTABLE_NOTIFY_H
#define METROTRK_PORTABLE_NOTIFY_H
#include "PowerPC_EABI_Support/MetroTRK/trk.h"
#ifdef __cplusplus
extern "C" {
#endif
DSError TRKDoNotifyStopped(MessageCommandID cmd);
#ifdef __cplusplus
}
#endif
#endif /* METROTRK_PORTABLE_NOTIFY_H */

View file

@ -0,0 +1,37 @@
#ifndef METROTRK_PORTABLE_NUBEVENT_H
#define METROTRK_PORTABLE_NUBEVENT_H
#include "PowerPC_EABI_Support/MetroTRK/trk.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef u32 NubEventID;
typedef struct TRKEvent {
NubEventType eventType;
NubEventID eventID;
MessageBufferID msgBufID;
} TRKEvent;
typedef struct TRKEventQueue {
int _00;
int count;
int next;
TRKEvent events[2];
NubEventID eventID;
} TRKEventQueue;
extern TRKEventQueue gTRKEventQueue;
BOOL TRKGetNextEvent(TRKEvent* event);
void TRKDestructEvent(TRKEvent*);
void TRKConstructEvent(TRKEvent*, NubEventType);
DSError TRKPostEvent(TRKEvent*);
DSError TRKInitializeEventQueue();
#ifdef __cplusplus
}
#endif
#endif /* METROTRK_PORTABLE_NUBEVENT_H */

View file

@ -0,0 +1,21 @@
#ifndef METROTRK_PORTABLE_NUBINIT_H
#define METROTRK_PORTABLE_NUBINIT_H
#include "PowerPC_EABI_Support/MetroTRK/trk.h"
#ifdef __cplusplus
extern "C" {
#endif
void TRKNubWelcome(void);
void TRKNubMainLoop(void);
DSError TRKTerminateNub(void);
DSError TRKInitializeNub(void);
extern BOOL gTRKBigEndian;
#ifdef __cplusplus
}
#endif
#endif /* METROTRK_PORTABLE_NUBINIT_H */

View file

@ -0,0 +1,23 @@
#ifndef METROTRK_PORTABLE_SERPOLL_H
#define METROTRK_PORTABLE_SERPOLL_H
#include "PowerPC_EABI_Support/MetroTRK/trk.h"
#ifdef __cplusplus
extern "C" {
#endif
DSError TRKInitializeSerialHandler(void);
DSError TRKTerminateSerialHandler(void);
void TRKGetInput(void);
MessageBufferID TRKTestForPacket();
void TRKProcessInput(int bufferIdx);
extern void* gTRKInputPendingPtr;
#ifdef __cplusplus
}
#endif
#endif /* METROTRK_PORTABLE_SERPOLL_H */

View file

@ -0,0 +1,29 @@
#ifndef METROTRK_PORTABLE_SUPPORT_H
#define METROTRK_PORTABLE_SUPPORT_H
#include "PowerPC_EABI_Support/MetroTRK/trk.h"
#include "stddef.h"
#ifdef __cplusplus
extern "C" {
#endif
DSError TRKSuppAccessFile(u32 file_handle, u8* data, size_t* count,
DSIOResult* io_result, BOOL need_reply, BOOL read);
DSError TRKRequestSend(TRKBuffer* msgBuf, int* bufferId, u32 p1, u32 p2,
int p3);
DSError HandleOpenFileSupportRequest(const char* path, u8 replyError,
u32* param_3, DSIOResult* ioResult);
DSError HandleCloseFileSupportRequest(int replyError, DSIOResult* ioResult);
DSError HandlePositionFileSupportRequest(DSReplyError replyErr, u32* param_2,
u8 param_3, DSIOResult* ioResult);
#ifdef __cplusplus
}
#endif
#endif /* METROTRK_PORTABLE_SUPPORT_H */

View file

@ -0,0 +1,24 @@
#ifndef OS_DOLPHIN_DOLPHIN_TRK_H
#define OS_DOLPHIN_DOLPHIN_TRK_H
#include "dolphin/types.h"
#include "PowerPC_EABI_Support/MetroTRK/trk.h"
#ifdef __cplusplus
extern "C" {
#endif
DSError TRKInitializeTarget();
void EnableMetroTRKInterrupts();
u32 TRKTargetTranslate(u32 param_0);
void TRK__read_aram(register int c, register u32 p2, void* p3);
void TRK__write_aram(register int c, register u32 p2, void* p3);
void __TRK_copy_vectors(void);
#ifdef __cplusplus
}
#endif
#endif /* OS_DOLPHIN_DOLPHIN_TRK_H */

View file

@ -0,0 +1,45 @@
#ifndef OS_DOLPHIN_DOLPHIN_TRK_GLUE_H
#define OS_DOLPHIN_DOLPHIN_TRK_GLUE_H
#include "dolphin/os.h"
#include "PowerPC_EABI_Support/MetroTRK/trk.h"
#include "stddef.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*DBCommFunc)(void);
typedef u32 (*DBPollFunc)(void);
typedef void (*DBCommInitFunc)(volatile u8**, __OSInterruptHandler);
typedef int (*DBCommReadFunc)(void*, size_t);
typedef int (*DBCommWriteFunc)(const void*, size_t);
typedef struct DBCommTable {
DBCommInitFunc initialize_func;
DBCommFunc init_interrupts_func;
DBPollFunc peek_func;
DBCommReadFunc read_func;
DBCommWriteFunc write_func;
DBCommFunc open_func;
DBCommFunc close_func;
} DBCommTable;
DSError TRKInitializeIntDrivenUART(u32 param_0, u32 param_1, u32 param_2,
volatile u8** param_3);
void UnreserveEXI2Port(void);
void ReserveEXI2Port(void);
int TRKPollUART(void);
UARTError TRKReadUARTN(void* bytes, u32 length);
UARTError TRKWriteUARTN(const void* bytes, u32 length);
void TRKLoadContext(OSContext* ctx, u32 r4);
int InitMetroTRKCommTable(int hwId);
void EnableEXI2Interrupts(void);
void TRK_board_display(char* str);
#ifdef __cplusplus
}
#endif
#endif /* OS_DOLPHIN_DOLPHIN_TRK_GLUE_H */

View file

@ -0,0 +1,16 @@
#ifndef OS_DOLPHIN_TARGCONT_H
#define OS_DOLPHIN_TARGCONT_H
#include "PowerPC_EABI_Support/MetroTRK/trk.h"
#ifdef __cplusplus
extern "C" {
#endif
DSError TRKTargetContinue(void);
#ifdef __cplusplus
}
#endif
#endif /* OS_DOLPHIN_TARGCONT_H */

View file

@ -0,0 +1,14 @@
#ifndef OS_DOLPHIN_USR_PUT_H
#define OS_DOLPHIN_USR_PUT_H
#ifdef __cplusplus
extern "C" {
#endif
void usr_put_initialize(void);
#ifdef __cplusplus
}
#endif
#endif /* OS_DOLPHIN_USR_PUT_H */

View file

@ -0,0 +1,16 @@
#ifndef PPC_GENERIC_FLUSH_CACHE_H
#define PPC_GENERIC_FLUSH_CACHE_H
#include <dolphin/types.h>
#ifdef __cplusplus
extern "C" {
#endif
void TRK_flush_cache(void* param_1, int param_2);
#ifdef __cplusplus
}
#endif
#endif /* PPC_GENERIC_FLUSH_CACHE_H */

View file

@ -0,0 +1,16 @@
#ifndef PPC_GENERIC_MPC_7XX_603E_H
#define PPC_GENERIC_MPC_7XX_603E_H
#include <dolphin/types.h>
#ifdef __cplusplus
extern "C" {
#endif
u32 TRKTargetCPUMinorType(void);
#ifdef __cplusplus
}
#endif
#endif /* PPC_GENERIC_MPC_7XX_603E_H */

View file

@ -0,0 +1,190 @@
#ifndef PPC_GENERIC_TARGIMPL_H
#define PPC_GENERIC_TARGIMPL_H
#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/nubevent.h"
#include "stddef.h"
#ifdef __cplusplus
extern "C" {
#endif
void TRKTargetSetInputPendingPtr(void* ptr);
void TRKSwapAndGo();
void TRKTargetSetStopped(unsigned int);
DSError TRKTargetInterrupt(TRKEvent*);
DSError TRKTargetSupportRequest();
void TRKDestructEvent(TRKEvent*);
DSError TRKTargetFlushCache(u8, void* start, void* end);
BOOL TRKTargetStopped(void);
DSError TRKTargetAddStopInfo(TRKBuffer* b);
DSError TRKTargetAddExceptionInfo(TRKBuffer* b);
DSError TRKTargetAccessARAM(u32 p1, u32 p2, u32* p3, BOOL read);
DSError TRKTargetAccessMemory(void* data, u32 start, size_t* length,
MemoryAccessOptions accessOptions, BOOL read);
DSError TRKTargetAccessDefault(u32 firstRegister, u32 lastRegister,
TRKBuffer* b, size_t* registersLengthPtr,
BOOL read);
DSError TRKTargetAccessFP(u32 firstRegister, u32 lastRegister, TRKBuffer* b,
size_t* registersLengthPtr, BOOL read);
DSError TRKTargetAccessExtended1(u32 firstRegister, u32 lastRegister,
TRKBuffer* b, size_t* registersLengthPtr,
BOOL read);
DSError TRKTargetAccessExtended2(u32 firstRegister, u32 lastRegister,
TRKBuffer* b, size_t* registerStorageSize,
BOOL read);
u32 TRKTargetGetPC();
DSError TRKTargetSingleStep(u32 count, BOOL stepOver);
DSError TRKTargetStepOutOfRange(u32 rangeStart, u32 rangeEnd, BOOL stepOver);
u32 TRKTargetStop();
void TRKInterruptHandler();
void TRKPostInterruptEvent(void);
typedef struct DSVersions {
u8 kernelMajor;
u8 kernelMinor;
u8 protocolMajor;
u8 protocolMinor;
} DSVersions;
DSError TRKTargetVersions(DSVersions* versions);
DSError TRKTargetSupportMask(u8 mask[32]);
typedef struct DSCPUType {
u8 cpuMajor;
u8 cpuMinor;
u8 bigEndian;
u8 defaultTypeSize;
u8 fpTypeSize;
u8 extended1TypeSize;
u8 extended2TypeSize;
} DSCPUType;
DSError TRKTargetCPUType(DSCPUType* cpuType);
typedef struct Default_PPC {
u32 GPR[32];
u32 PC;
u32 LR;
u32 CR;
u32 CTR;
u32 XER;
} Default_PPC;
typedef struct Float_PPC {
u64 FPR[32];
u64 FPSCR;
u64 FPECR;
} Float_PPC;
typedef struct Extended1_PPC_6xx_7xx {
u32 SR[16];
u32 TBL;
u32 TBU;
u32 HID0;
u32 HID1;
u32 MSR;
u32 PVR;
u32 IBAT0U;
u32 IBAT0L;
u32 IBAT1U;
u32 IBAT1L;
u32 IBAT2U;
u32 IBAT2L;
u32 IBAT3U;
u32 IBAT3L;
u32 DBAT0U;
u32 DBAT0L;
u32 DBAT1U;
u32 DBAT1L;
u32 DBAT2U;
u32 DBAT2L;
u32 DBAT3U;
u32 DBAT3L;
u32 DMISS;
u32 DCMP;
u32 HASH1;
u32 HASH2;
u32 IMISS;
u32 ICMP;
u32 RPA;
u32 SDR1;
u32 DAR;
u32 DSISR;
u32 SPRG0;
u32 SPRG1;
u32 SPRG2;
u32 SPRG3;
u32 DEC;
u32 IABR;
u32 EAR;
u32 DABR;
u32 PMC1;
u32 PMC2;
u32 PMC3;
u32 PMC4;
u32 SIA;
u32 MMCR0;
u32 MMCR1;
u32 THRM1;
u32 THRM2;
u32 THRM3;
u32 ICTC;
u32 L2CR;
u32 UMMCR2;
u32 UBAMR;
u32 UMMCR0;
u32 UPMC1;
u32 UPMC2;
u32 USIA;
u32 UMMCR1;
u32 UPMC3;
u32 UPMC4;
u32 USDA;
u32 MMCR2;
u32 BAMR;
u32 SDA;
u32 MSSCR0;
u32 MSSCR1;
u32 PIR;
u32 exceptionID;
u32 GQR[8];
u32 HID_G;
u32 WPAR;
u32 DMA_U;
u32 DMA_L;
} Extended1_PPC_6xx_7xx;
typedef struct Extended2_PPC_6xx_7xx {
u32 PSR[32][2];
} Extended2_PPC_6xx_7xx;
typedef struct ProcessorState_PPC_6xx_7xx {
Default_PPC Default;
Float_PPC Float;
Extended1_PPC_6xx_7xx Extended1;
Extended2_PPC_6xx_7xx Extended2;
u32 transport_handler_saved_ra;
} ProcessorState_PPC_6xx_7xx;
typedef ProcessorState_PPC_6xx_7xx ProcessorState_PPC;
extern ProcessorState_PPC gTRKCPUState;
typedef struct TRKState {
u32 gpr[32]; // _00
u32 lr; // _80
u32 ctr; // _84
u32 xer; // _88
u32 msr; // _8C
u32 dar; // _90
u32 dsisr; // _94
BOOL isStopped; // _98
BOOL inputActivated; // _9C
void* inputPendingPtr; // _A0
} TRKState;
extern TRKState gTRKState;
#ifdef __cplusplus
}
#endif
#endif /* PPC_GENERIC_TARGIMPL_H */