diff --git a/config/GMPE01_00/splits.txt b/config/GMPE01_00/splits.txt index 6b38187f..fc3ba2b8 100644 --- a/config/GMPE01_00/splits.txt +++ b/config/GMPE01_00/splits.txt @@ -1186,7 +1186,7 @@ TRK_MINNOW_DOLPHIN/serpoll.c: .text start:0x800ECC5C end:0x800ED028 .bss start:0x801A9110 end:0x801A9128 -TRK_MINNOW_DOLPHIN/usrput.c: +TRK_MINNOW_DOLPHIN/usr_put.c: .text start:0x800ED028 end:0x800ED0B4 TRK_MINNOW_DOLPHIN/dispatch.c: @@ -1224,7 +1224,7 @@ TRK_MINNOW_DOLPHIN/targimpl.c: TRK_MINNOW_DOLPHIN/targsupp.c: .text start:0x800F1CF0 end:0x800F1D10 -TRK_MINNOW_DOLPHIN/__exception.c: +TRK_MINNOW_DOLPHIN/__exception.s: .init start:0x80003534 end:0x80005468 TRK_MINNOW_DOLPHIN/dolphin_trk.c: diff --git a/config/GMPE01_01/splits.txt b/config/GMPE01_01/splits.txt index 6b38187f..fc3ba2b8 100644 --- a/config/GMPE01_01/splits.txt +++ b/config/GMPE01_01/splits.txt @@ -1186,7 +1186,7 @@ TRK_MINNOW_DOLPHIN/serpoll.c: .text start:0x800ECC5C end:0x800ED028 .bss start:0x801A9110 end:0x801A9128 -TRK_MINNOW_DOLPHIN/usrput.c: +TRK_MINNOW_DOLPHIN/usr_put.c: .text start:0x800ED028 end:0x800ED0B4 TRK_MINNOW_DOLPHIN/dispatch.c: @@ -1224,7 +1224,7 @@ TRK_MINNOW_DOLPHIN/targimpl.c: TRK_MINNOW_DOLPHIN/targsupp.c: .text start:0x800F1CF0 end:0x800F1D10 -TRK_MINNOW_DOLPHIN/__exception.c: +TRK_MINNOW_DOLPHIN/__exception.s: .init start:0x80003534 end:0x80005468 TRK_MINNOW_DOLPHIN/dolphin_trk.c: diff --git a/configure.py b/configure.py index 545739bb..22c85a12 100644 --- a/configure.py +++ b/configure.py @@ -242,6 +242,9 @@ cflags_trk = [ "-sdata 0", "-sdata2 0", "-inline auto,deferred", + "-pool off", + "-enum min", + "-sdatathreshold 0" ] cflags_odemuexi = [ @@ -344,6 +347,16 @@ def DolphinLib(lib_name, objects): } +def DolphinLibUnpatched(lib_name, objects): + return { + "lib": lib_name, + "mw_version": "GC/1.2.5", + "cflags": cflags_dolphin, + "host": False, + "objects": objects, + } + + def MusyX(objects, mw_version="GC/1.3.2", debug=False, major=1, minor=5, patch=4): cflags = cflags_musyx if not debug else cflags_musyx_debug return { @@ -514,14 +527,14 @@ config.libs = [ Object(MatchingFor("GMPE01_00", "GMPE01_01"), "dolphin/db.c"), ], ), - DolphinLib( + DolphinLibUnpatched( "mtx", [ - Object(NonMatching, "dolphin/mtx/mtx.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "dolphin/mtx/mtx.c"), Object(MatchingFor("GMPE01_00", "GMPE01_01"), "dolphin/mtx/mtxvec.c"), Object(MatchingFor("GMPE01_00", "GMPE01_01"), "dolphin/mtx/mtx44.c"), - Object(NonMatching, "dolphin/mtx/vec.c"), - Object(NonMatching, "dolphin/mtx/quat.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "dolphin/mtx/vec.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "dolphin/mtx/quat.c"), Object(MatchingFor("GMPE01_00", "GMPE01_01"), "dolphin/mtx/psmtx.c"), ], ), @@ -554,7 +567,7 @@ config.libs = [ DolphinLib( "pad", [ - Object(NonMatching, "dolphin/pad/Padclamp.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "dolphin/pad/Padclamp.c"), Object(MatchingFor("GMPE01_00", "GMPE01_01"), "dolphin/pad/Pad.c"), ], ), @@ -582,12 +595,12 @@ config.libs = [ DolphinLib( "gx", [ - Object(NonMatching, "dolphin/gx/GXInit.c"), - Object(NonMatching, "dolphin/gx/GXFifo.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "dolphin/gx/GXInit.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "dolphin/gx/GXFifo.c"), Object(MatchingFor("GMPE01_00", "GMPE01_01"), "dolphin/gx/GXAttr.c"), Object(MatchingFor("GMPE01_00", "GMPE01_01"), "dolphin/gx/GXMisc.c"), - Object(NonMatching, "dolphin/gx/GXGeometry.c"), - Object(NonMatching, "dolphin/gx/GXFrameBuf.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "dolphin/gx/GXGeometry.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "dolphin/gx/GXFrameBuf.c"), Object(MatchingFor("GMPE01_00", "GMPE01_01"), "dolphin/gx/GXLight.c"), Object(MatchingFor("GMPE01_00", "GMPE01_01"), "dolphin/gx/GXTexture.c"), Object(MatchingFor("GMPE01_00", "GMPE01_01"), "dolphin/gx/GXBump.c"), @@ -669,7 +682,7 @@ config.libs = [ "objects": [ Object(NonMatching, "MSL_C.PPCEABI.bare.H/abort_exit.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/alloc.c"), - Object(NonMatching, "MSL_C.PPCEABI.bare.H/errno.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "MSL_C.PPCEABI.bare.H/errno.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/ansi_files.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/ansi_fp.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/arith.c"), @@ -683,7 +696,7 @@ config.libs = [ Object(NonMatching, "MSL_C.PPCEABI.bare.H/mem_funcs.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/misc_io.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/printf.c"), - Object(NonMatching, "MSL_C.PPCEABI.bare.H/float.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "MSL_C.PPCEABI.bare.H/float.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/signal.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/string.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/uart_console_io.c"), @@ -702,14 +715,14 @@ config.libs = [ Object(NonMatching, "MSL_C.PPCEABI.bare.H/s_copysign.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/s_cos.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/s_floor.c"), - Object(NonMatching, "MSL_C.PPCEABI.bare.H/s_frexp.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "MSL_C.PPCEABI.bare.H/s_frexp.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/s_ldexp.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/s_modf.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/s_sin.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/s_tan.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/w_acos.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/w_asin.c"), - Object(NonMatching, "MSL_C.PPCEABI.bare.H/w_atan2.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "MSL_C.PPCEABI.bare.H/w_atan2.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/w_fmod.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/w_pow.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/math_ppc.c"), @@ -721,28 +734,28 @@ config.libs = [ "cflags": cflags_trk, "host": False, "objects": [ - Object(NonMatching, "TRK_MINNOW_DOLPHIN/mainloop.c"), - Object(NonMatching, "TRK_MINNOW_DOLPHIN/nubevent.c"), - Object(NonMatching, "TRK_MINNOW_DOLPHIN/nubinit.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "TRK_MINNOW_DOLPHIN/mainloop.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "TRK_MINNOW_DOLPHIN/nubevent.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "TRK_MINNOW_DOLPHIN/nubinit.c"), Object(NonMatching, "TRK_MINNOW_DOLPHIN/msg.c"), Object(NonMatching, "TRK_MINNOW_DOLPHIN/msgbuf.c"), Object(NonMatching, "TRK_MINNOW_DOLPHIN/serpoll.c"), - Object(NonMatching, "TRK_MINNOW_DOLPHIN/usrput.c"), + Object(NonMatching, "TRK_MINNOW_DOLPHIN/usr_put.c"), Object(NonMatching, "TRK_MINNOW_DOLPHIN/dispatch.c"), Object(NonMatching, "TRK_MINNOW_DOLPHIN/msghndlr.c"), Object(NonMatching, "TRK_MINNOW_DOLPHIN/support.c"), - Object(NonMatching, "TRK_MINNOW_DOLPHIN/mutex_TRK.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "TRK_MINNOW_DOLPHIN/mutex_TRK.c"), Object(NonMatching, "TRK_MINNOW_DOLPHIN/notify.c"), - Object(NonMatching, "TRK_MINNOW_DOLPHIN/flush_cache.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "TRK_MINNOW_DOLPHIN/flush_cache.c"), Object(NonMatching, "TRK_MINNOW_DOLPHIN/mem_TRK.c"), Object(NonMatching, "TRK_MINNOW_DOLPHIN/targimpl.c"), Object(NonMatching, "TRK_MINNOW_DOLPHIN/targsupp.c"), - Object(NonMatching, "TRK_MINNOW_DOLPHIN/__exception.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "TRK_MINNOW_DOLPHIN/__exception.s"), Object(NonMatching, "TRK_MINNOW_DOLPHIN/dolphin_trk.c"), - Object(NonMatching, "TRK_MINNOW_DOLPHIN/mpc_7xx_603e.c"), - Object(NonMatching, "TRK_MINNOW_DOLPHIN/main_TRK.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "TRK_MINNOW_DOLPHIN/mpc_7xx_603e.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "TRK_MINNOW_DOLPHIN/main_TRK.c"), Object(NonMatching, "TRK_MINNOW_DOLPHIN/dolphin_trk_glue.c"), - Object(NonMatching, "TRK_MINNOW_DOLPHIN/targcont.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "TRK_MINNOW_DOLPHIN/targcont.c"), Object(NonMatching, "TRK_MINNOW_DOLPHIN/target_options.c"), Object(NonMatching, "TRK_MINNOW_DOLPHIN/mslsupp.c"), ], diff --git a/include/OdemuExi2/odemuexi/DebuggerDriver.h b/include/OdemuExi2/odemuexi/DebuggerDriver.h new file mode 100644 index 00000000..71a27ed3 --- /dev/null +++ b/include/OdemuExi2/odemuexi/DebuggerDriver.h @@ -0,0 +1,24 @@ +#ifndef ODEMUEXI_DEBUGGER_DRIVER_H +#define ODEMUEXI_DEBUGGER_DRIVER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int Hu_IsStub(); + +void DBInitComm(volatile u8** param_1, __OSInterruptHandler param_2); +void DBInitInterrupts(void); +u32 DBQueryData(void); +int DBRead(void* data, u32 size); +int DBWrite(const void* data, u32 size); +void DBOpen(void); +void DBClose(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/PowerPC_EABI_Support/MetroTRK/trk.h b/include/PowerPC_EABI_Support/MetroTRK/trk.h new file mode 100644 index 00000000..c8814672 --- /dev/null +++ b/include/PowerPC_EABI_Support/MetroTRK/trk.h @@ -0,0 +1,381 @@ +#ifndef __METROTRK_TRK_H__ +#define __METROTRK_TRK_H__ + +#include "dolphin/types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +//////////// TRK ENUMS ///////////// +// Hardware types. +typedef enum { + HARDWARE_AMC_DDH = 0, + HARDWARE_GDEV = 1, + HARDWARE_BBA = 2, +} HardwareType; + +// DS Error returns. +enum { + DS_NoError = 0x0, + DS_StepError = 0x1, + DS_ParameterError = 0x2, + + DS_EventQueueFull = 0x100, + + DS_NoMessageBufferAvailable = 0x300, + DS_MessageBufferOverflow = 0x301, + DS_MessageBufferReadError = 0x302, + + DS_DispatchError = 0x500, + + DS_InvalidMemory = 0x700, + DS_InvalidRegister = 0x701, + DS_CWDSException = 0x702, + DS_UnsupportedError = 0x703, + DS_InvalidProcessID = 0x704, + DS_InvalidThreadID = 0x705, + DS_OSError = 0x706, + + DS_Error800 = 0x800, +}; + +typedef int DSError; + +// Where to read/write. +typedef enum { + DS_Stdin = 0, + DS_Stdout = 1, + DS_Stderr = 2, +} DSFileHandle; + +// IO returns. +typedef enum { + DS_IONoError = 0, + DS_IOError = 1, + DS_IOEOF = 2, +} DSIOResult; + +// Message command IDs +typedef enum { + DSMSG_Ping = 0x0, + DSMSG_Connect = 0x1, + DSMSG_Disconnect = 0x2, + DSMSG_Reset = 0x3, + DSMSG_Versions = 0x4, + DSMSG_SupportMask = 0x5, + DSMSG_Override = 0x7, + + DSMSG_ReadMemory = 0x10, + DSMSG_WriteMemory = 0x11, + DSMSG_ReadRegisters = 0x12, + DSMSG_WriteRegisters = 0x13, + DSMSG_SetOption = 0x17, + DSMSG_Continue = 0x18, + DSMSG_Step = 0x19, + DSMSG_Stop = 0x1A, + + DSMSG_ReplyACK = 0x80, + + DSMSG_NotifyStopped = 0x90, + DSMSG_NotifyException = 0x91, + + DSMSG_WriteFile = 0xD0, + DSMSG_ReadFile = 0xD1, + DSMSG_OpenFile = 0xD2, + DSMSG_CloseFile = 0xD3, + DSMSG_PositionFile = 0xD4, + + DSMSG_ReplyNAK = 0xFF, +} MessageCommandID; + +// Register commands. +typedef enum { + DSREG_Default = 0, + DSREG_FP = 1, + DSREG_Extended1 = 2, + DSREG_Extended2 = 3, +} DSMessageRegisterOptions; + +// Step commands. +typedef enum { + DSSTEP_IntoCount = 0x0, + DSSTEP_IntoRange = 0x1, + DSSTEP_OverCount = 0x10, + DSSTEP_OverRange = 0x11, +} DSMessageStepOptions; + +typedef enum { + DSREPLY_NoError = 0x0, + DSREPLY_Error = 0x1, + DSREPLY_PacketSizeError = 0x2, + DSREPLY_CWDSError = 0x3, + DSREPLY_EscapeError = 0x4, + DSREPLY_BadFCS = 0x5, + DSREPLY_Overflow = 0x6, + DSREPLY_SequenceMissing = 0x7, + + DSREPLY_UnsupportedCommandError = 0x10, + DSREPLY_ParameterError = 0x11, + DSREPLY_UnsupportedOptionError = 0x12, + DSREPLY_InvalidMemoryRange = 0x13, + DSREPLY_InvalidRegisterRange = 0x14, + DSREPLY_CWDSException = 0x15, + DSREPLY_NotStopped = 0x16, + DSREPLY_BreakpointsFull = 0x17, + DSREPLY_BreakpointConflict = 0x18, + + DSREPLY_OSError = 0x20, + DSREPLY_InvalidProcessID = 0x21, + DSREPLY_InvalidThreadID = 0x22, + DSREPLY_DebugSecurityError = 0x23, +} DSReplyError; + +typedef enum { + DSRECV_Wait = 0, + DSRECV_Found = 1, + DSRECV_InFrame = 2, + DSRECV_FrameOverflow = 3, +} ReceiverState; + +typedef enum { + DSMSGMEMORY_Segmented = 0x01, /* non-flat addr space */ + DSMSGMEMORY_Extended = 0x02, /* > 32-bit data addr */ + DSMSGMEMORY_Protected = 0x04, /* non-user memory */ + DSMSGMEMORY_Userview = 0x08, /* breakpoints are invisible */ + DSMSGMEMORY_Space_program = 0x00, + DSMSGMEMORY_Space_data = 0x40, + DSMSGMEMORY_Space_io = 0x80 +}; + +typedef enum { + NUBEVENT_Null = 0, + NUBEVENT_Shutdown = 1, + NUBEVENT_Request = 2, + NUBEVENT_Breakpoint = 3, + NUBEVENT_Exception = 4, + NUBEVENT_Support = 5, +} NubEventType; + +typedef enum { + VALIDMEM_Readable = 0, + VALIDMEM_Writeable = 1, +} ValidMemoryOptions; + +typedef enum { + MEMACCESS_UserMemory = 0, + MEMACCESS_DebuggerMemory = 1, +} MemoryAccessOptions; + +typedef int UARTError; + +typedef enum { + UART_NoError = 0, + UART_UnknownBaudRate = 1, + UART_ConfigurationError = 2, + UART_BufferOverflow = 3, // specified buffer was too small + UART_NoData = 4, // no data available from polling +} UARTErrorOptions; + +typedef enum { + kBaudHWSet = -1, // use HW settings such as DIP switches + kBaud300 = 300, // valid baud rates + kBaud600 = 600, + kBaud1200 = 1200, + kBaud1800 = 1800, + kBaud2000 = 2000, + kBaud2400 = 2400, + kBaud3600 = 3600, + kBaud4800 = 4800, + kBaud7200 = 7200, + kBaud9600 = 9600, + kBaud19200 = 19200, + kBaud38400 = 38400, + kBaud57600 = 57600, + kBaud115200 = 115200, + kBaud230400 = 230400 +} UARTBaudRate; + +//////////////////////////////////// + +typedef int MessageBufferID; + +#define TRKMSGBUF_SIZE (0x800 + 0x80) + +typedef struct TRKBuffer { + /* 0x00 */ u32 mutex; + /* 0x04 */ BOOL isInUse; + /* 0x08 */ u32 length; + /* 0x0C */ u32 position; + /* 0x10 */ u8 data[TRKMSGBUF_SIZE]; +} TRKBuffer; + +typedef struct TRKFramingState { + MessageBufferID msgBufID; // _00 + TRKBuffer* buffer; // _04 + ReceiverState receiveState; // _08 + BOOL isEscape; // _0C + u8 fcsType; // _10 +} TRKFramingState; + +typedef struct TRKState_PPC { + u32 GPR[32]; // 0x0 + u32 LR; // 0x80 + u32 CTR; // 0x84 + u32 XER; // 0x88 + u32 MSR; // 0x8c + u32 DAR; // 0x90 + u32 DSISR; // 0x94 + BOOL stopped; // 0x98 + BOOL inputActivated; // 0x9c + u8* inputPendingPtr; // 0xA0 +} TRKState_PPC; + +typedef struct CommandReply { + u32 _00; // _00 + union { + u8 b; + MessageCommandID m; + } commandID; // _04, use MessageCommandID enum + union { + u8 b; + DSReplyError r; + } replyError; // _08, use DSReplyError enum - should be enum type? check + // size. + u32 _0C; // _0C + u8 _10[0x30]; // _10, unknown +} CommandReply; + +typedef struct ProcessorRestoreFlags_PPC { + u8 TBR; + u8 DEC; + u8 linker_padding[0x9 - 0x2]; +} ProcessorRestoreFlags_PPC; + +void TRKSaveExtended1Block(); + +#define SPR_XER 1 +#define SPR_LR 8 +#define SPR_CTR 9 +#define SPR_DSISR 18 +#define SPR_DAR 19 +#define SPR_DEC 22 +#define SPR_SDR1 25 +#define SPR_SRR0 26 +#define SPR_SRR1 27 +#define SPR_SPRG0 272 +#define SPR_SPRG1 273 +#define SPR_SPRG2 274 +#define SPR_SPRG3 275 +#define SPR_EAR 282 +#define SPR_TBL 284 +#define SPR_TBU 285 +#define SPR_PVR 287 +#define SPR_IBAT0U 528 +#define SPR_IBAT0L 529 +#define SPR_IBAT1U 530 +#define SPR_IBAT1L 531 +#define SPR_IBAT2U 532 +#define SPR_IBAT2L 533 +#define SPR_IBAT3U 534 +#define SPR_IBAT3L 535 +#define SPR_IBAT4U 560 +#define SPR_IBAT4L 561 +#define SPR_IBAT5U 562 +#define SPR_IBAT5L 563 +#define SPR_IBAT6U 564 +#define SPR_IBAT6L 565 +#define SPR_IBAT7U 566 +#define SPR_IBAT7L 567 +#define SPR_DBAT0U 536 +#define SPR_DBAT0L 537 +#define SPR_DBAT1U 538 +#define SPR_DBAT1L 539 +#define SPR_DBAT2U 540 +#define SPR_DBAT2L 541 +#define SPR_DBAT3U 542 +#define SPR_DBAT3L 543 +#define SPR_DBAT4U 568 +#define SPR_DBAT4L 569 +#define SPR_DBAT5U 570 +#define SPR_DBAT5L 571 +#define SPR_DBAT6U 572 +#define SPR_DBAT6L 573 +#define SPR_DBAT7U 574 +#define SPR_DBAT7L 575 +#define SPR_GQR0 912 +#define SPR_GQR1 913 +#define SPR_GQR2 914 +#define SPR_GQR3 915 +#define SPR_GQR4 916 +#define SPR_GQR5 917 +#define SPR_GQR6 918 +#define SPR_GQR7 919 +#define SPR_HID2 920 +#define SPR_WPAR 921 +#define SPR_DMA_U 922 +#define SPR_DMA_L 923 +#define SPR_UMMCR0 936 +#define SPR_UPMC1 937 +#define SPR_UPMC2 938 +#define SPR_USIA 939 +#define SPR_UMMCR1 940 +#define SPR_UPMC3 941 +#define SPR_UPMC4 942 +#define SPR_USDA 943 +#define SPR_MMCR0 952 +#define SPR_PMC1 953 +#define SPR_PMC2 954 +#define SPR_SIA 955 +#define SPR_MMCR1 956 +#define SPR_PMC3 957 +#define SPR_PMC4 958 +#define SPR_SDA 959 +#define SPR_HID0 1008 +#define SPR_HID1 1009 +#define SPR_IABR 1010 +#define SPR_HID4 1011 +#define SPR_DABR 1013 +#define SPR_L2CR 1017 +#define SPR_ICTC 1019 +#define SPR_THRM1 1020 +#define SPR_THRM2 1021 +#define SPR_FPECR 1022 + +// PPC exceptions +// 0x000 is reserved +#define PPC_SystemReset 0x100 +#define PPC_MachineCheck 0x200 +#define PPC_DataStorage 0x300 +#define PPC_InstructionStorage 0x400 +#define PPC_ExternalInterrupt 0x500 +#define PPC_Alignment 0x600 +#define PPC_Program 0x700 +#define PPC_FloatingPointUnavaiable 0x800 +#define PPC_Decrementer 0x900 +// 0xA00-0xB00 are reserved +#define PPC_SystemCall 0xC00 +#define PPC_Trace 0xD00 +#define PPC_FloatingPointAssist 0xE00 // unimplemented in 750CL +#define PPC_PerformanceMonitor 0xF00 // Dolphin/Broadway specific +// 0x1000-0x1200 are unimplemented in 750CL +#define PPC_InstructionAddressBreakpoint 0x1300 // Dolphin/Broadway specific +// 0x1400-0x2F00 are reserved, but TRK uses some +#define PPC_SystemManagementInterrupt 0x1400 +// 0x1500-0x1600 are unimplemented in 750CL +#define PPC_ThermalManagementInterrupt 0x1700 +#define PPC_1800Exception 0x1800 +#define PPC_1900Exception 0x1900 +#define PPC_1A00Exception 0x1A00 +#define PPC_1B00Exception 0x1B00 +#define PPC_1C00Exception 0x1C00 // Data breakpoint? +#define PPC_1D00Exception 0x1D00 // Instruction breakpoint? +#define PPC_1E00Exception 0x1E00 // Peripheral breakpoint? +#define PPC_1F00Exception 0x1F00 // Non maskable development port? +#define PPC_2000Exception 0x2000 + +#ifdef __cplusplus +} +#endif + +#endif /* __METROTRK_TRK_H__ */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/FILE_POS.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/FILE_POS.h new file mode 100644 index 00000000..046471d5 --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/FILE_POS.h @@ -0,0 +1,18 @@ +#ifndef _MSL_COMMON_FILE_POS_H +#define _MSL_COMMON_FILE_POS_H + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int fseek(FILE* file, unsigned long offset, int mode); +int _fseek(FILE* file, fpos_t offset, int mode); +long ftell(FILE* file); + +#ifdef __cplusplus +} +#endif + +#endif /* _MSL_COMMON_FILE_POS_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/abort_exit.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/abort_exit.h new file mode 100644 index 00000000..7c62fe70 --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/abort_exit.h @@ -0,0 +1,17 @@ +#ifndef _MSL_COMMON_ABORT_EXIT_H +#define _MSL_COMMON_ABORT_EXIT_H + +#ifdef __cplusplus +extern "C" { +#endif + +void exit(int status); +void abort(void); + +extern void (*__stdio_exit)(void); + +#ifdef __cplusplus +}; +#endif + +#endif /* _MSL_COMMON_ABORT_EXIT_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/alloc.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/alloc.h new file mode 100644 index 00000000..6b08d6f9 --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/alloc.h @@ -0,0 +1,16 @@ +#ifndef _MSL_COMMON_ALLOC_H +#define _MSL_COMMON_ALLOC_H + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void free(void* ptr); + +#ifdef __cplusplus +} +#endif + +#endif /* _MSL_COMMON_ALLOC_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h new file mode 100644 index 00000000..f06c55df --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h @@ -0,0 +1,133 @@ +#ifndef _MSL_COMMON_ANSI_FILES_H +#define _MSL_COMMON_ANSI_FILES_H + +#include "stddef.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 + +typedef unsigned long __file_handle; +typedef unsigned long fpos_t; +#ifndef __cplusplus +typedef unsigned short wchar_t; +#endif + +#define set_error(file) \ + do { \ + (file)->file_state.error = 1; \ + (file)->buffer_length = 0; \ + } while (0) + +enum __file_kinds { + __closed_file, + __disk_file, + __console_file, + __string_file, + __unavailable_file, +}; + +enum __file_orientation { + /* 0x0 */ UNORIENTED, + /* 0x1 */ CHAR_ORIENTED, + /* 0x2 */ WIDE_ORIENTED, +}; + +typedef struct _file_modes { + unsigned int open_mode : 2; + unsigned int io_mode : 3; + unsigned int buffer_mode : 2; + unsigned int file_kind : 3; + unsigned int file_orientation : 2; + unsigned int binary_io : 1; +} file_modes; + +enum __io_modes { + __read = 1, + __write = 2, + __read_write = 3, + __append = 4, +}; + +enum __io_states { + __neutral, + __writing, + __reading, + __rereading, +}; + +enum __io_results { + __no_io_error, + __io_error, + __io_EOF, +}; + +typedef struct _file_states { + unsigned int io_state : 3; + unsigned int free_buffer : 1; + unsigned char eof; + unsigned char error; +} file_states; + +typedef void (*__idle_proc)(void); +typedef int (*__pos_proc)(__file_handle file, fpos_t* position, int mode, + __idle_proc idle_proc); +typedef int (*__io_proc)(__file_handle file, unsigned char* buff, size_t* count, + __idle_proc idle_proc); +typedef int (*__close_proc)(__file_handle file); + +typedef struct _FILE { + __file_handle handle; + file_modes file_mode; + file_states file_state; + + char char_buffer; + char char_buffer_overflow; + char ungetc_buffer[2]; + wchar_t ungetc_wide_buffer[2]; + + unsigned long position; + unsigned char* buffer; + unsigned long buffer_size; + unsigned char* buffer_ptr; + unsigned long buffer_length; + unsigned long buffer_alignment; + unsigned long save_buffer_length; + unsigned long buffer_position; + + __pos_proc position_fn; + __io_proc read_fn; + __io_proc write_fn; + __close_proc close_fn; + __idle_proc idle_fn; +} FILE; + +typedef struct _files { + FILE _stdin; + FILE _stdout; + FILE _stderr; +} files; + +#define _IONBF 0 +#define _IOLBF 1 +#define _IOFBF 2 + +extern files __files; +extern int __close_console(__file_handle file); +extern int __write_console(__file_handle file, unsigned char* buf, + size_t* count, __idle_proc idle_fn); +extern int __read_console(__file_handle file, unsigned char* buf, size_t* count, + __idle_proc idle_fn); + +unsigned int __flush_all(void); +void __close_all(void); + +#ifdef __cplusplus +}; +#endif + +#endif /* _MSL_COMMON_ANSI_FILES_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_fp.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_fp.h new file mode 100644 index 00000000..90ba7acf --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_fp.h @@ -0,0 +1,36 @@ +#ifndef _MSL_COMMON_ANSI_FP_H +#define _MSL_COMMON_ANSI_FP_H + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/float.h" + +#define SIGDIGLEN 36 + +typedef struct decimal { + char sign; + char unk1; + short exp; + struct { + unsigned char length; + unsigned char text[36]; + unsigned char unk41; + } sig; +} decimal; + +typedef struct decform { + char style; + char unk1; + short digits; +} decform; + +/* void __ull2dec(decimal*, u64); +void __timesdec(decimal*, const decimal*, const decimal*); +void __str2dec(decimal*, const char*, short); +void __two_exp(decimal*, s16); +BOOL __equals_dec(const decimal*, const decimal*); +BOOL __less_dec(const decimal*, const decimal*); +void __minus_dec(decimal*, const decimal*, const decimal*); +void __num2dec_internal(decimal*, f64); +void __num2dec(const decform*, f64, decimal*); +f64 __dec2num(const decimal*); */ + +#endif diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/arith.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/arith.h new file mode 100644 index 00000000..317dfa0d --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/arith.h @@ -0,0 +1,19 @@ +#ifndef _MSL_COMMON_ARITH_H +#define _MSL_COMMON_ARITH_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + int quot; /* quotient */ + int rem; /* remainder */ +} div_t; + +div_t div(int numerator, int denominator); + +#ifdef __cplusplus +} +#endif + +#endif /* _MSL_COMMON_ARITH_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/buffer_io.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/buffer_io.h new file mode 100644 index 00000000..85ad160a --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/buffer_io.h @@ -0,0 +1,11 @@ +#ifndef _MSL_COMMON_BUFFER_IO_H +#define _MSL_COMMON_BUFFER_IO_H + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" + +enum { __align_buffer, __dont_align_buffer }; + +void __prep_buffer(FILE* file); +int __flush_buffer(FILE* file, size_t* bytes_flushed); + +#endif /* _MSL_COMMON_BUFFER_IO_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/char_io.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/char_io.h new file mode 100644 index 00000000..e3733cf7 --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/char_io.h @@ -0,0 +1,17 @@ +#ifndef _MSL_COMMON_CHAR_IO_H +#define _MSL_COMMON_CHAR_IO_H + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int fputs(const char* str, FILE* stream); +int __put_char(int c, FILE* stream); + +#ifdef __cplusplus +} +#endif + +#endif /* _MSL_COMMON_CHAR_IO_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/critical_regions.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/critical_regions.h new file mode 100644 index 00000000..e4456725 --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/critical_regions.h @@ -0,0 +1,30 @@ +#ifndef _MSL_COMMON_CRITICAL_REGIONS_H +#define _MSL_COMMON_CRITICAL_REGIONS_H + +#ifdef __cplusplus +extern "C" { +#endif + +enum critical_regions { + atexit_funcs_access, + malloc_pool_access, + stdin_access, + stdout_access, + stderr_access, + files_access, + console_status_access, + signal_funcs_access, + thread_access, + num_critical_regions +}; + +void __init_critical_regions(void); +void __kill_critical_regions(void); +void __begin_critical_region(int region); +void __end_critical_region(int region); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ctype.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ctype.h new file mode 100644 index 00000000..0bb0356e --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ctype.h @@ -0,0 +1,76 @@ +#ifndef _MSL_COMMON_CTYPE_H +#define _MSL_COMMON_CTYPE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define EOF -1L + +extern const unsigned char __ctype_map[]; +extern const unsigned char __lower_map[]; +extern const unsigned char __upper_map[]; + +#define __control_char 0x01 +#define __motion_char 0x02 +#define __space_char 0x04 +#define __punctuation 0x08 +#define __digit 0x10 +#define __hex_digit 0x20 +#define __lower_case 0x40 +#define __upper_case 0x80 + +#define __letter (__lower_case | __upper_case) +#define __alphanumeric (__letter | __digit) +#define __graphic (__alphanumeric | __punctuation) +#define __printable (__graphic | __space_char) +#define __whitespace (__motion_char | __space_char) +#define __control (__motion_char | __control_char) +#define __zero_fill(c) ((int)(unsigned char)(c)) + +int tolower(int c); +int toupper(int c); + +inline int isalpha(int c) +{ + return (int)(__ctype_map[(unsigned char)c] & __letter); +} +inline int isdigit(int c) +{ + return (int)(__ctype_map[(unsigned char)c] & __digit); +} +inline int isspace(int c) +{ + return (int)(__ctype_map[(unsigned char)c] & __whitespace); +} +inline int isupper(int c) +{ + return (int)(__ctype_map[(unsigned char)c] & __upper_case); +} +inline int isxdigit(int c) +{ + return (int)(__ctype_map[(unsigned char)c] & __hex_digit); +} + +inline int _tolower(int c) +{ + return (c == -1 ? -1 : (int)__lower_map[(unsigned char)c]); +} + +#ifdef __cplusplus +}; + +namespace std { +inline int tolower(int c) +{ + return (c == -1 ? -1 : (int)__lower_map[(unsigned char)c]); +} +inline int toupper(int c) +{ + return (c == -1 ? -1 : (int)__upper_map[(unsigned char)c]); +} +}; // namespace std + +#endif + +#endif /* _MSL_COMMON_CTYPE_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/direct_io.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/direct_io.h new file mode 100644 index 00000000..7e838551 --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/direct_io.h @@ -0,0 +1,17 @@ +#ifndef _MSL_COMMON_DIRECT_IO_H +#define _MSL_COMMON_DIRECT_IO_H + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" + +#ifdef __cplusplus +extern "C" { +#endif + +size_t __fwrite(const void* buffer, size_t size, size_t count, FILE* stream); +size_t fwrite(const void* buffer, size_t size, size_t count, FILE* stream); + +#ifdef __cplusplus +} +#endif + +#endif /* _MSL_COMMON_DIRECT_IO_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/errno.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/errno.h new file mode 100644 index 00000000..269d896d --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/errno.h @@ -0,0 +1,20 @@ +#ifndef MSL_COMMON_SRC_ERRNO_H +#define MSL_COMMON_SRC_ERRNO_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define ENOERR 0 +#define EDOM 33 +#define ERANGE 34 +#define EFPOS 40 +#define ESIGPARM 36 + +extern int errno; + +#ifdef __cplusplus +} +#endif + +#endif /* MSL_COMMON_SRC_ERRNO_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/extras.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/extras.h new file mode 100644 index 00000000..4d8e8b62 --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/extras.h @@ -0,0 +1,15 @@ +#ifndef _MSL_COMMON_EXTRAS_H +#define _MSL_COMMON_EXTRAS_H + +#ifdef __cplusplus +extern "C" { +#endif + +int strnicmp(const char* str1, const char* str2, int n); +int stricmp(const char* str1, const char* str2); + +#ifdef __cplusplus +} +#endif + +#endif /* _MSL_COMMON_EXTRAS_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/file_io.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/file_io.h new file mode 100644 index 00000000..a06e7cef --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/file_io.h @@ -0,0 +1,18 @@ +#ifndef _MSL_COMMON_FILE_IO_H +#define _MSL_COMMON_FILE_IO_H + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int __msl_strnicmp(const char* str1, const char* str2, int n); +int fflush(FILE* file); +int fclose(FILE* file); + +#ifdef __cplusplus +} +#endif + +#endif /* _MSL_COMMON_FILE_IO_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/float.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/float.h new file mode 100644 index 00000000..14d34342 --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/float.h @@ -0,0 +1,92 @@ +#ifndef _MSL_COMMON_FLOAT_H +#define _MSL_COMMON_FLOAT_H + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common_Embedded/Math/fdlibm.h" + +#define FP_SNAN 0 +#define FP_QNAN 1 +#define FP_INFINITE 2 +#define FP_ZERO 3 +#define FP_NORMAL 4 +#define FP_SUBNORMAL 5 + +#define FP_NAN FP_QNAN + +#define fpclassify(x) \ + ((sizeof(x) == sizeof(float)) ? __fpclassifyf(x) : __fpclassifyd(x)) +#define signbit(x) \ + ((sizeof(x) == sizeof(float)) ? __signbitf(x) : __signbitd(x)) +#define isfinite(x) ((fpclassify(x) > 2)) +#define isnan(x) ((fpclassify(x) == FP_NAN)) +#define isinf(x) ((fpclassify(x) == FP_INFINITE)) + +#define __signbitf(x) ((int)(__HI(x) & 0x80000000)) + +// TODO: OK? +#define __signbitd(x) ((int)(__HI(x) & 0x80000000)) + +extern unsigned long __float_nan[]; +extern unsigned long __float_huge[]; +extern unsigned long __float_max[]; +extern unsigned long __float_epsilon[]; + +inline int __fpclassifyf(float __value) +{ + unsigned long integer = *(unsigned long*)&__value; + + switch (integer & 0x7f800000) { + case 0x7f800000: + if ((integer & 0x7fffff) != 0) { + return FP_QNAN; + } + return FP_INFINITE; + + case 0: + if ((integer & 0x7fffff) != 0) { + return FP_SUBNORMAL; + } + return FP_ZERO; + } + + return FP_NORMAL; +} + +inline int __fpclassifyd(double __value) +{ + switch (__HI(__value) & 0x7ff00000) { + case 0x7ff00000: { + if ((__HI(__value) & 0x000fffff) || (__LO(__value) & 0xffffffff)) + return FP_QNAN; + else + return FP_INFINITE; + break; + } + case 0: { + if ((__HI(__value) & 0x000fffff) || (__LO(__value) & 0xffffffff)) + return FP_SUBNORMAL; + else + return FP_ZERO; + break; + } + } + return FP_NORMAL; +} + +#define FLT_MANT_DIG 24 +#define FLT_DIG 6 +#define FLT_MIN_EXP (-125) +#define FLT_MIN_10_EXP (-37) +#define FLT_MAX_EXP 128 +#define FLT_MAX_10_EXP 38 + +#define FLT_MAX 3.40282346638528860e+38f +#define FLT_EPSILON 1.1920928955078125e-07f + +#define DBL_MANT_DIG 53 +#define DBL_DIG 15 +#define DBL_MIN_EXP (-1021) +#define DBL_MIN_10_EXP (-308) +#define DBL_MAX_EXP 1024 +#define DBL_MAX_10_EXP 308 + +#endif /* _MSL_COMMON_FLOAT_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/limits.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/limits.h new file mode 100644 index 00000000..2b8b756f --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/limits.h @@ -0,0 +1,93 @@ +#ifndef _STD_LIMITS_H +#define _STD_LIMITS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define CHAR_BIT 8 + +#define SCHAR_MIN (-0x7F - 1) +#define SCHAR_MAX 0x7F +#define UCHAR_MAX 0xFF + +#define CHAR_MIN 0 +#define CHAR_MAX SCHAR_MAX + +#define SHRT_MIN (-0x7FFF - 1) +#define SHRT_MAX 0x7FFF +#define USHRT_MAX 0xFFFF + +#define INT_MIN (-0x7FFFFFFF - 1) +#define INT_MAX 0x7FFFFFFF +#define UINT_MAX 0xFFFFFFFF + +#define LONG_MIN (-0x7FFFFFFFL - 1) +#define LONG_MAX 0x7FFFFFFFL +#define ULONG_MAX 0xFFFFFFFFUL + +#define LLONG_MIN (-0x7FFFFFFFFFFFFFFFLL - 1) +#define LLONG_MAX 0x7FFFFFFFFFFFFFFFLL +#define ULLONG_MAX 0xFFFFFFFFFFFFFFFFULL + +#ifdef __cplusplus +} + +namespace std { +template class numeric_limits { +public: + inline static T min(); + inline static T max(); +}; + +template <> class numeric_limits { +public: + inline static char min() { return -0x80; } + inline static char max() { return 0x7F; } +}; + +template <> class numeric_limits { +public: + inline static short min() { return -0x8000; } + inline static short max() { return 0x7FFF; } +}; + +template <> class numeric_limits { +public: + inline static int min() { return -0x80000000; } + inline static int max() { return 0x7FFFFFFF; } +}; + +template <> class numeric_limits { +public: + inline static long min() { return -0x80000000; } + inline static long max() { return 0x7FFFFFFF; } +}; + +template <> class numeric_limits { +public: + inline static unsigned char min() { return 0x0; } + inline static unsigned char max() { return 0xFF; } +}; + +template <> class numeric_limits { +public: + inline static unsigned short min() { return 0x0; } + inline static unsigned short max() { return 0xFFFF; } +}; + +template <> class numeric_limits { +public: + inline static unsigned int min() { return 0x0; } + inline static unsigned int max() { return 0xFFFFFFFF; } +}; + +template <> class numeric_limits { +public: + inline static unsigned long min() { return 0x0; } + inline static unsigned long max() { return 0xFFFFFFFF; } +}; + +} // namespace std +#endif +#endif diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/math.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/math.h new file mode 100644 index 00000000..e99949cc --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/math.h @@ -0,0 +1,106 @@ +#ifndef MSL_MATH_H_ +#define MSL_MATH_H_ + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/float.h" + +#define NAN (*(float*)__float_nan) +#define HUGE_VALF (*(float*)__float_huge) + +#define M_PI 3.14159265358979323846f +#define M_SQRT3 1.73205f + +#define DEG_TO_RAD(degrees) (degrees * (M_PI / 180.0f)) +#define RAD_TO_DEG(radians) \ + (radians \ + * (180.0f / M_PI + 0.000005f)) // the 0.000005f is probably a fakematch + +#ifdef __cplusplus +extern "C" { +#endif + +int abs(int); +double acos(double); +float acosf(float); +double asin(double); +double atan(double); +double atan2(double, double); +double ceil(double); +double copysign(double, double); +double cos(double); +float cosf(float); +double exp(double); + +extern double __fabs(double); +extern float __fabsf(float); +inline double fabs(double f) { return __fabs(f); } + +double __frsqrte(double); +float __fres(float); + +double floor(double); +double fmod(double, double); + +double frexp(double, int*); +double ldexp(double, int); +double modf(double, double*); +double pow(double, double); +double sin(double); +float sinf(float); +double tan(double); +float tanf(float); + +extern inline double sqrt(double x) +{ + if (x > 0.0) { + double guess = __frsqrte(x); /* returns an approximation to */ + guess + = .5 * guess * (3.0 - guess * guess * x); /* now have 8 sig bits */ + guess + = .5 * guess * (3.0 - guess * guess * x); /* now have 16 sig bits */ + guess + = .5 * guess * (3.0 - guess * guess * x); /* now have 32 sig bits */ + guess = .5 * guess + * (3.0 - guess * guess * x); /* now have > 53 sig bits */ + return x * guess; + } else if (x == 0) + return 0; + else if (x) + return NAN; + + return HUGE_VALF; +} + +#ifdef __cplusplus +}; + +namespace std { +inline float fabsf(float f) { return fabs(f); } +inline float abs(float f) { return fabsf(f); } +inline float fmodf(float x, float y) { return fmod(x, y); } +inline float atan2f(float y, float x) { return (float)atan2(y, x); } +inline float sinf(float x) { return sin(x); } +inline float cosf(float x) { return cos(x); } +inline float tanf(float x) { return tan(x); } + +extern inline float sqrtf(float x) +{ + const double _half = .5; + const double _three = 3.0; + volatile float y; + if (x > 0.0f) { + double guess = __frsqrte((double)x); // returns an approximation to + guess = _half * guess + * (_three - guess * guess * x); // now have 12 sig bits + guess = _half * guess + * (_three - guess * guess * x); // now have 24 sig bits + guess = _half * guess + * (_three - guess * guess * x); // now have 32 sig bits + y = (float)(x * guess); + return y; + } + return x; +} +}; // namespace std +#endif + +#endif diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mbstring.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mbstring.h new file mode 100644 index 00000000..2aa9f4ea --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mbstring.h @@ -0,0 +1,16 @@ +#ifndef _MSL_COMMON_MBSTRING_H +#define _MSL_COMMON_MBSTRING_H + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/wchar_io.h" + +#ifdef __cplusplus +extern "C" { +#endif + +size_t wcstombs(char* dst, const wchar_t* src, size_t n); + +#ifdef __cplusplus +} +#endif + +#endif /* _MSL_COMMON_MBSTRING_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mem_funcs.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mem_funcs.h new file mode 100644 index 00000000..0e245466 --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mem_funcs.h @@ -0,0 +1,19 @@ +#ifndef _MSL_COMMON_MEM_FUNCS_H +#define _MSL_COMMON_MEM_FUNCS_H + +#include "stddef.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void __copy_longs_rev_unaligned(void* dst, const void* src, size_t n); +void __copy_longs_unaligned(void* dst, const void* src, size_t n); +void __copy_longs_rev_aligned(void* dst, const void* src, size_t n); +void __copy_longs_aligned(void* dst, const void* src, size_t n); + +#ifdef __cplusplus +} +#endif + +#endif /* _MSL_COMMON_MEM_FUNCS_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/misc_io.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/misc_io.h new file mode 100644 index 00000000..715f282a --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/misc_io.h @@ -0,0 +1,14 @@ +#ifndef _MSL_COMMON_MISC_IO_H +#define _MSL_COMMON_MISC_IO_H + +#ifdef __cplusplus +extern "C" { +#endif + +void __stdio_atexit(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _MSL_COMMON_MISC_IO_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/printf.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/printf.h new file mode 100644 index 00000000..e716867f --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/printf.h @@ -0,0 +1,22 @@ +#ifndef _MSL_COMMON_PRINTF_H +#define _MSL_COMMON_PRINTF_H + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" +#include "stdarg.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int fprintf(FILE* stream, const char* format, ...); +int printf(const char* format, ...); +int sprintf(char* s, const char* format, ...); +int snprintf(char* s, size_t n, const char* format, ...); +int vsnprintf(char* s, size_t n, const char* format, va_list arg); +int vprintf(const char* format, va_list arg); + +#ifdef __cplusplus +} +#endif + +#endif /* _MSL_COMMON_PRINTF_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/scanf.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/scanf.h new file mode 100644 index 00000000..c6451e34 --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/scanf.h @@ -0,0 +1,43 @@ +#ifndef _MSL_COMMON_SCANF_H +#define _MSL_COMMON_SCANF_H + +#include "stddef.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" + +#ifdef __cplusplus +extern "C" { +#endif + +enum __ReadProcActions { __GetAChar, __UngetAChar, __TestForError }; + +enum __WReadProcActions { __GetAwChar, __UngetAwChar, __TestForwcsError }; + +typedef struct { + char* CharStr; + size_t MaxCharCount; + size_t CharsWritten; +} __OutStrCtrl; + +typedef struct { + char* NextChar; + int NullCharDetected; +} __InStrCtrl; + +typedef struct { + wchar_t* wCharStr; + size_t MaxCharCount; + size_t CharsWritten; +} __wOutStrCtrl; + +typedef struct { + wchar_t* wNextChar; + int wNullCharDetected; +} __wInStrCtrl; + +int __StringRead(void* str, int ch, int behavior); + +#ifdef __cplusplus +} +#endif + +#endif /* _MSL_COMMON_SCANF_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/signal.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/signal.h new file mode 100644 index 00000000..58fc22ab --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/signal.h @@ -0,0 +1,16 @@ +#ifndef _MSL_COMMON_SIGNAL_H +#define _MSL_COMMON_SIGNAL_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*__signal_func_ptr)(int); + +int raise(int sig); + +#ifdef __cplusplus +} +#endif + +#endif /* _MSL_COMMON_SIGNAL_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdio.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdio.h new file mode 100644 index 00000000..89806588 --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdio.h @@ -0,0 +1,13 @@ +#ifndef MSL_STDIO_H_ +#define MSL_STDIO_H_ + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/char_io.h" // IWYU pragma: export +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/file_io.h" // IWYU pragma: export +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/printf.h" // IWYU pragma: export +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/extras.h" // IWYU pragma: export + +#define stdin (&__files._stdin) +#define stdout (&__files._stdout) +#define stderr (&__files._stderr) + +#endif diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdlib.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdlib.h new file mode 100644 index 00000000..9df0be5b --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdlib.h @@ -0,0 +1,9 @@ +#ifndef MSL_STDLIB_H_ +#define MSL_STDLIB_H_ + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/abort_exit.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/arith.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mbstring.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/strtoul.h" + +#endif diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/strtoul.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/strtoul.h new file mode 100644 index 00000000..843ee863 --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/strtoul.h @@ -0,0 +1,18 @@ +#ifndef _MSL_COMMON_STRTOUL_H +#define _MSL_COMMON_STRTOUL_H + +#ifdef __cplusplus +extern "C" { +#endif + +long strtol(const char* str, char** end, int base); +unsigned long strtoul(const char* str, char** end, int base); +unsigned long __strtoul(int base, int max_width, + int (*ReadProc)(void*, int, int), void* ReadProcArg, + int* chars_scanned, int* negative, int* overflow); + +#ifdef __cplusplus +} +#endif + +#endif /* _MSL_COMMON_STRTOUL_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/wchar_io.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/wchar_io.h new file mode 100644 index 00000000..90153f95 --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/wchar_io.h @@ -0,0 +1,12 @@ +#ifndef _MSL_COMMON_WCHAR_IO_H +#define _MSL_COMMON_WCHAR_IO_H + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" + +#ifndef __cplusplus +typedef unsigned short wchar_t; +#endif + +int fwide(FILE* file, int mode); + +#endif /* _MSL_COMMON_WCHAR_IO_H */ diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common_Embedded/Math/fdlibm.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common_Embedded/Math/fdlibm.h new file mode 100644 index 00000000..1f654aa7 --- /dev/null +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common_Embedded/Math/fdlibm.h @@ -0,0 +1,234 @@ +#ifndef _FDLIBM_H +#define _FDLIBM_H + +/* @(#)fdlibm.h 1.5 04/04/22 */ +/** + * ==================================================== + * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. + * + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#ifdef __cplusplus +extern "C" { +#endif // ifdef __cplusplus + +/* Sometimes it's necessary to define __LITTLE_ENDIAN explicitly + but these catch some common cases. */ + +#if defined(i386) || defined(i486) || defined(intel) || defined(x86) \ + || defined(i86pc) || defined(__alpha) || defined(__osf__) +#define __LITTLE_ENDIAN +#endif + +#ifdef __LITTLE_ENDIAN +#define __HI(x) *(1 + (int*)&x) +#define __LO(x) *(int*)&x +#define __HIp(x) *(1 + (int*)x) +#define __LOp(x) *(int*)x +#else +#define __HI(x) *(int*)&x +#define __LO(x) *(1 + (int*)&x) +#define __HIp(x) *(int*)x +#define __LOp(x) *(1 + (int*)x) +#endif + +// NOTE: should be enabled according to w_atan2.c +#define _IEEE_LIBM + +// TODO: should __STDC__ actually be defined? +// #ifdef __STDC__ +#define __P(p) p +// #else +// #define __P(p) () +// #endif + +/** + * ANSI/POSIX + */ + +extern int signgam; + +#define MAXFLOAT ((f32)3.40282346638528860e+38) + +enum fdversion { fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix }; + +#define _LIB_VERSION_TYPE enum fdversion +#define _LIB_VERSION _fdlib_version + +/* if global variable _LIB_VERSION is not desirable, one may + * change the following to be a constant by: + * #define _LIB_VERSION_TYPE const enum version + * In that case, after one initializes the value _LIB_VERSION (see + * s_lib_version.c) during compile time, it cannot be modified + * in the middle of a program + */ +extern _LIB_VERSION_TYPE _LIB_VERSION; + +#define _IEEE_ fdlibm_ieee +#define _SVID_ fdlibm_svid +#define _XOPEN_ fdlibm_xopen +#define _POSIX_ fdlibm_posix + +struct exception { + int type; + char* name; + double arg1; + double arg2; + double retval; +}; + +#define HUGE MAXFLOAT + +/** + * set X_TLOSS = pi*2**52, which is possibly defined in + * (one may replace the following line by "#include ") + */ + +#define X_TLOSS 1.41484755040568800000e+16 + +#define DOMAIN 1 +#define SING 2 +#define OVERFLOW 3 +#define UNDERFLOW 4 +#define TLOSS 5 +#define PLOSS 6 + +/** + * ANSI/POSIX + */ +extern double acos __P((double)); +extern double asin __P((double)); +extern double atan __P((double)); +extern double atan2 __P((double, double)); +extern double cos __P((double)); +extern double sin __P((double)); +extern double tan __P((double)); + +extern double cosh __P((double)); +extern double sinh __P((double)); +extern double tanh __P((double)); + +extern double exp __P((double)); +extern double frexp __P((double, int*)); +extern double ldexp __P((double, int)); +extern double scalbn __P((double, int)); +extern double log __P((double)); +extern double log10 __P((double)); +extern double modf __P((double, double*)); + +extern double pow __P((double, double)); +extern double sqrt __P((double)); + +extern double ceil __P((double)); +extern double fabs __P((double)); +// NOTE: I have no idea how they got it to mangle like this +extern double fabs__Fd(double); +extern double floor __P((double)); +extern double fmod __P((double, double)); + +extern double erf __P((double)); +extern double erfc __P((double)); +extern double gamma __P((double)); +extern double hypot __P((double, double)); +extern int isnan __P((double)); +extern int finite __P((double)); +extern double j0 __P((double)); +extern double j1 __P((double)); +extern double jn __P((int, double)); +extern double lgamma __P((double)); +extern double y0 __P((double)); +extern double y1 __P((double)); +extern double yn __P((int, double)); + +extern double acosh __P((double)); +extern double asinh __P((double)); +extern double atanh __P((double)); +extern double cbrt __P((double)); +extern double logb __P((double)); +extern double nextafter __P((double, double)); +extern double remainder __P((double, double)); +#ifdef _SCALB_INT +extern double scalb __P((double, int)); +#else +extern double scalb __P((double, double)); +#endif + +extern int matherr __P((struct exception*)); + +/** + * IEEE Test Vector + */ +extern double significand __P((double)); + +/** + * Functions callable from C, intended to support IEEE arithmetic. + */ +extern double copysign __P((double, double)); +extern int ilogb __P((double)); +extern double rint __P((double)); +extern double scalbn __P((double, int)); + +/** + * BSD math library entry points + */ +extern double expm1 __P((double)); +extern double log1p __P((double)); + +/** + * Reentrant version of gamma & lgamma; passes signgam back by reference + * as the second argument; user must allocate space for signgam. + */ +#ifdef _REENTRANT +extern double gamma_r __P((double, int*)); +extern double lgamma_r __P((double, int*)); +#endif /* _REENTRANT */ + +/* ieee style elementary functions */ +extern double __ieee754_sqrt __P((double)); +extern double __ieee754_acos __P((double)); +extern double __ieee754_acosh __P((double)); +extern double __ieee754_log __P((double)); +extern double __ieee754_atanh __P((double)); +extern double __ieee754_asin __P((double)); +extern double __ieee754_atan2 __P((double, double)); +extern double __ieee754_exp __P((double)); +extern double __ieee754_cosh __P((double)); +extern double __ieee754_fmod __P((double, double)); +extern double __ieee754_pow __P((double, double)); +extern double __ieee754_lgamma_r __P((double, int*)); +extern double __ieee754_gamma_r __P((double, int*)); +extern double __ieee754_lgamma __P((double)); +extern double __ieee754_gamma __P((double)); +extern double __ieee754_log10 __P((double)); +extern double __ieee754_sinh __P((double)); +extern double __ieee754_hypot __P((double, double)); +extern double __ieee754_j0 __P((double)); +extern double __ieee754_j1 __P((double)); +extern double __ieee754_y0 __P((double)); +extern double __ieee754_y1 __P((double)); +extern double __ieee754_jn __P((int, double)); +extern double __ieee754_yn __P((int, double)); +extern double __ieee754_remainder __P((double, double)); +extern int __ieee754_rem_pio2 __P((double, double*)); +#ifdef _SCALB_INT +extern double __ieee754_scalb __P((double, int)); +#else +extern double __ieee754_scalb __P((double, double)); +#endif + +/* fdlibm kernel function */ +extern double __kernel_standard __P((double, double, int)); +extern double __kernel_sin __P((double, double, int)); +extern double __kernel_cos __P((double, double)); +extern double __kernel_tan __P((double, double, int)); +extern int __kernel_rem_pio2 __P((double*, double*, int, int, int, const int*)); + +#ifdef __cplusplus +}; +#endif // ifdef __cplusplus + +#endif diff --git a/include/PowerPC_EABI_Support/Runtime/MWCPlusLib.h b/include/PowerPC_EABI_Support/Runtime/MWCPlusLib.h new file mode 100644 index 00000000..8d78b551 --- /dev/null +++ b/include/PowerPC_EABI_Support/Runtime/MWCPlusLib.h @@ -0,0 +1,44 @@ +#ifndef _RUNTIME_MWCPLUSLIB_H +#define _RUNTIME_MWCPLUSLIB_H + +#include "stddef.h" + +#define CTORARG_TYPE int +#define CTORARG_PARTIAL (0) +#define CTORARG_COMPLETE (1) + +#define CTORCALL_COMPLETE(ctor, objptr) \ + (((void (*)(void*, CTORARG_TYPE))ctor)(objptr, CTORARG_COMPLETE)) + +#define DTORARG_TYPE int + +#define DTORCALL_COMPLETE(dtor, objptr) \ + (((void (*)(void*, DTORARG_TYPE))dtor)(objptr, -1)) +#define DTORCALL_PARTIAL(dtor, objptr) \ + (((void (*)(void*, DTORARG_TYPE))dtor)(objptr, 0)) + +typedef void* ConstructorDestructor; + +#ifdef __cplusplus +extern "C" { +#endif + +extern void* __copy(char* to, char* from, size_t size); + +extern void __construct_array(void* ptr, ConstructorDestructor ctor, + ConstructorDestructor dtor, size_t size, + size_t n); +extern void __destroy_arr(void* block, ConstructorDestructor* dtor, size_t size, + size_t n); +extern void* __construct_new_array(void* block, ConstructorDestructor ctor, + ConstructorDestructor dtor_arg, size_t size, + size_t n); +extern void __destroy_new_array(void* block, ConstructorDestructor dtor); +extern void __destroy_new_array2(); +extern void __destroy_new_array3(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/PowerPC_EABI_Support/Runtime/NMWException.h b/include/PowerPC_EABI_Support/Runtime/NMWException.h new file mode 100644 index 00000000..2358f785 --- /dev/null +++ b/include/PowerPC_EABI_Support/Runtime/NMWException.h @@ -0,0 +1,43 @@ +#ifndef _NMWEXCEPTION +#define _NMWEXCEPTION + +typedef short vbase_ctor_arg_type; +typedef char local_cond_type; + +typedef struct CatchInfo { + void* location; + void* typeinfo; + void* dtor; + void* sublocation; + long pointercopy; + void* stacktop; +} CatchInfo; + +typedef struct DestructorChain { + struct DestructorChain* next; + void* destructor; + void* object; +} DestructorChain; + +#ifdef __cplusplus +extern "C" { +#endif + +extern void* __register_global_object(void* object, void* destructor, + void* registration); +extern void __destroy_global_chain(void); + +extern void __end__catch(CatchInfo* catchinfo); +extern void __throw(char* throwtype, void* location, void* dtor); +extern char __throw_catch_compare(const char* throwtype, const char* catchtype, + long* offset_result); +extern void __unexpected(CatchInfo* catchinfo); + +extern int __register_fragment(struct __eti_init_info* info, char* TOC); +extern void __unregister_fragment(int fragmentID); + +#ifdef __cplusplus +} +#endif + +#endif // _NMWEXCEPTION diff --git a/include/PowerPC_EABI_Support/Runtime/__mem.h b/include/PowerPC_EABI_Support/Runtime/__mem.h new file mode 100644 index 00000000..0a885b8f --- /dev/null +++ b/include/PowerPC_EABI_Support/Runtime/__mem.h @@ -0,0 +1,17 @@ +#ifndef _RUNTIME_MEM_H +#define _RUNTIME_MEM_H + +#include "stddef.h" + +#ifdef __cplusplus +extern "C" { +#endif + +__declspec(section ".init") void* memcpy(void* dest, const void* src, size_t n); +__declspec(section ".init") void* memset(void* dest, int val, size_t count); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/PowerPC_EABI_Support/Runtime/__ppc_eabi_linker.h b/include/PowerPC_EABI_Support/Runtime/__ppc_eabi_linker.h new file mode 100644 index 00000000..a2fa3d63 --- /dev/null +++ b/include/PowerPC_EABI_Support/Runtime/__ppc_eabi_linker.h @@ -0,0 +1,72 @@ +#ifndef __PPC_EABI_LINKER +#define __PPC_EABI_LINKER + +__declspec(section ".init") extern char _stack_addr[]; +__declspec(section ".init") extern char _stack_end[]; +__declspec(section ".init") extern char _heap_addr[]; +__declspec(section ".init") extern char _heap_end[]; +__declspec(section ".init") extern const char _fextabindex_rom[]; +__declspec(section ".init") extern char _fextabindex[]; +__declspec(section ".init") extern char _eextabindex[]; + +__declspec(section ".init") extern char _SDA_BASE_[]; + +__declspec(section ".init") extern char _SDA2_BASE_[]; + +typedef struct __rom_copy_info { + char* rom; + char* addr; + unsigned int size; +} __rom_copy_info; + +__declspec(section ".init") extern __rom_copy_info _rom_copy_info[]; + +typedef struct __bss_init_info { + char* addr; + unsigned int size; +} __bss_init_info; + +__declspec(section ".init") extern __bss_init_info _bss_init_info[]; + +typedef struct __eti_init_info { + void* eti_start; + void* eti_end; + void* code_start; + unsigned long code_size; +} __eti_init_info; + +__declspec(section ".init") extern __eti_init_info _eti_init_info[]; +__declspec(section ".init") extern const char _f_init_rom[]; +__declspec(section ".init") extern char _f_init[]; +__declspec(section ".init") extern char _e_init[]; +__declspec(section ".init") extern const char _f_text_rom[]; +__declspec(section ".init") extern char _f_text[]; +__declspec(section ".init") extern char _e_text[]; +__declspec(section ".init") extern const char _f_rodata_rom[]; +__declspec(section ".init") extern char _f_rodata[]; +__declspec(section ".init") extern char _e_rodata[]; +__declspec(section ".init") extern const char _fextab_rom[]; +__declspec(section ".init") extern char _fextab[]; +__declspec(section ".init") extern char _eextab[]; +__declspec(section ".init") extern const char _f_data_rom[]; +__declspec(section ".init") extern char _f_data[]; +__declspec(section ".init") extern char _e_data[]; +__declspec(section ".init") extern char _f_bss[]; +__declspec(section ".init") extern char _e_bss[]; +__declspec(section ".init") extern const char _f_sdata_rom[]; +__declspec(section ".init") extern char _f_sdata[]; +__declspec(section ".init") extern char _e_sdata[]; +__declspec(section ".init") extern char _f_sbss[]; +__declspec(section ".init") extern char _e_sbss[]; +__declspec(section ".init") extern const char _f_sdata2_rom[]; +__declspec(section ".init") extern char _f_sdata2[]; +__declspec(section ".init") extern char _e_sdata2[]; +__declspec(section ".init") extern char _f_sbss2[]; +__declspec(section ".init") extern char _e_sbss2[]; +__declspec(section ".init") extern const char _f_PPC_EMB_sdata0_rom[]; +__declspec(section ".init") extern char _f_PPC_EMB_sdata0[]; +__declspec(section ".init") extern char _e_PPC_EMB_sdata0[]; +__declspec(section ".init") extern char _f_PPC_EMB_sbss0[]; +__declspec(section ".init") extern char _e_PPC_EMB_sbss0[]; + +#endif // __PPC_EABI_LINKER diff --git a/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/dispatch.h b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/dispatch.h new file mode 100644 index 00000000..0861cde2 --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/dispatch.h @@ -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 */ diff --git a/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/main_TRK.h b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/main_TRK.h new file mode 100644 index 00000000..9ff3a2da --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/main_TRK.h @@ -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 */ diff --git a/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/mainloop.h b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/mainloop.h new file mode 100644 index 00000000..606a4437 --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/mainloop.h @@ -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 */ diff --git a/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/mem_TRK.h b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/mem_TRK.h new file mode 100644 index 00000000..aeef9c7d --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/mem_TRK.h @@ -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 */ diff --git a/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msg.h b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msg.h new file mode 100644 index 00000000..8433ef8d --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msg.h @@ -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 */ diff --git a/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msgbuf.h b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msgbuf.h new file mode 100644 index 00000000..770d3886 --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msgbuf.h @@ -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 */ diff --git a/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msghndlr.h b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msghndlr.h new file mode 100644 index 00000000..aa8abff5 --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msghndlr.h @@ -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 */ diff --git a/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/mutex_TRK.h b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/mutex_TRK.h new file mode 100644 index 00000000..7297cf18 --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/mutex_TRK.h @@ -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 */ diff --git a/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/notify.h b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/notify.h new file mode 100644 index 00000000..459830f9 --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/notify.h @@ -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 */ diff --git a/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/nubevent.h b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/nubevent.h new file mode 100644 index 00000000..da5a012b --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/nubevent.h @@ -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 */ diff --git a/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/nubinit.h b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/nubinit.h new file mode 100644 index 00000000..9f1d4174 --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/nubinit.h @@ -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 */ diff --git a/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/serpoll.h b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/serpoll.h new file mode 100644 index 00000000..40636776 --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/serpoll.h @@ -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 */ diff --git a/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/support.h b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/support.h new file mode 100644 index 00000000..5f8e9fbc --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/MetroTRK/Portable/support.h @@ -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 */ diff --git a/include/TRK_MINNOW_DOLPHIN/Os/dolphin/dolphin_trk.h b/include/TRK_MINNOW_DOLPHIN/Os/dolphin/dolphin_trk.h new file mode 100644 index 00000000..fa3a575a --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/Os/dolphin/dolphin_trk.h @@ -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 */ diff --git a/include/TRK_MINNOW_DOLPHIN/Os/dolphin/dolphin_trk_glue.h b/include/TRK_MINNOW_DOLPHIN/Os/dolphin/dolphin_trk_glue.h new file mode 100644 index 00000000..550454cc --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/Os/dolphin/dolphin_trk_glue.h @@ -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 */ diff --git a/include/TRK_MINNOW_DOLPHIN/Os/dolphin/targcont.h b/include/TRK_MINNOW_DOLPHIN/Os/dolphin/targcont.h new file mode 100644 index 00000000..1d1c4417 --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/Os/dolphin/targcont.h @@ -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 */ diff --git a/include/TRK_MINNOW_DOLPHIN/Os/dolphin/usr_put.h b/include/TRK_MINNOW_DOLPHIN/Os/dolphin/usr_put.h new file mode 100644 index 00000000..d01cc0b1 --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/Os/dolphin/usr_put.h @@ -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 */ diff --git a/include/TRK_MINNOW_DOLPHIN/ppc/Generic/flush_cache.h b/include/TRK_MINNOW_DOLPHIN/ppc/Generic/flush_cache.h new file mode 100644 index 00000000..a512aacf --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/ppc/Generic/flush_cache.h @@ -0,0 +1,16 @@ +#ifndef PPC_GENERIC_FLUSH_CACHE_H +#define PPC_GENERIC_FLUSH_CACHE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void TRK_flush_cache(void* param_1, int param_2); + +#ifdef __cplusplus +} +#endif + +#endif /* PPC_GENERIC_FLUSH_CACHE_H */ diff --git a/include/TRK_MINNOW_DOLPHIN/ppc/Generic/mpc_7xx_603e.h b/include/TRK_MINNOW_DOLPHIN/ppc/Generic/mpc_7xx_603e.h new file mode 100644 index 00000000..ec764776 --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/ppc/Generic/mpc_7xx_603e.h @@ -0,0 +1,16 @@ +#ifndef PPC_GENERIC_MPC_7XX_603E_H +#define PPC_GENERIC_MPC_7XX_603E_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +u32 TRKTargetCPUMinorType(void); + +#ifdef __cplusplus +} +#endif + +#endif /* PPC_GENERIC_MPC_7XX_603E_H */ diff --git a/include/TRK_MINNOW_DOLPHIN/ppc/Generic/targimpl.h b/include/TRK_MINNOW_DOLPHIN/ppc/Generic/targimpl.h new file mode 100644 index 00000000..e7ce7015 --- /dev/null +++ b/include/TRK_MINNOW_DOLPHIN/ppc/Generic/targimpl.h @@ -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 */ diff --git a/include/amcstubs/AmcExi2Stubs.h b/include/amcstubs/AmcExi2Stubs.h new file mode 100644 index 00000000..48298c34 --- /dev/null +++ b/include/amcstubs/AmcExi2Stubs.h @@ -0,0 +1,27 @@ +#ifndef AMCEXI2STUBS_H +#define AMCEXI2STUBS_H + +#include "dolphin/os.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef __OSInterruptHandler AmcEXICallback; + +typedef enum { AMC_EXI_NO_ERROR = 0, AMC_EXI_UNSELECTED } AmcExiError; + +void EXI2_Init(volatile u8**, AmcEXICallback); +void EXI2_EnableInterrupts(void); +u32 EXI2_Poll(void); +int EXI2_ReadN(void*, u32); +int EXI2_WriteN(const void*, u32); +void EXI2_Reserve(void); +void EXI2_Unreserve(void); +BOOL AMC_IsStub(void); + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/include/dolphin/math.h b/include/dolphin/math.h new file mode 100644 index 00000000..483d8081 --- /dev/null +++ b/include/dolphin/math.h @@ -0,0 +1,85 @@ +#ifndef _DOLPHIN_MATH +#define _DOLPHIN_MATH + +// this file is necessary to match mtx/quat.c + +#define M_PI 3.141592653589793 + +#ifndef _MATH_INLINE +#define _MATH_INLINE static inline +#endif + +extern int __float_nan[]; +extern int __float_huge[]; +extern int __double_huge[]; + +#define INFINITY (*(float *)__float_huge) +#define NAN (*(float *)__float_nan) +#define HUGE_VAL (*(double *)__double_huge) + +#ifdef __MWERKS__ +extern inline double sqrt(double x) +{ + if (x > 0.0) { + double guess = __frsqrte(x); /* returns an approximation to */ + guess = .5 * guess * (3.0 - guess * guess * x); /* now have 8 sig bits */ + guess = .5 * guess * (3.0 - guess * guess * x); /* now have 16 sig bits */ + guess = .5 * guess * (3.0 - guess * guess * x); /* now have 32 sig bits */ + guess = .5 * guess * (3.0 - guess * guess * x); /* now have > 53 sig bits */ + return x * guess; + } + else if (x == 0) + return 0; + else if (x) + return NAN; + + return INFINITY; +} + +extern inline float sqrtf(float x) +{ + const double _half = .5; + const double _three = 3.0; + volatile float y; + if (x > 0.0f) { + double guess = __frsqrte((double)x); // returns an approximation to + guess = _half * guess * (_three - guess * guess * x); // now have 12 sig bits + guess = _half * guess * (_three - guess * guess * x); // now have 24 sig bits + guess = _half * guess * (_three - guess * guess * x); // now have 32 sig bits + y = (float)(x * guess); + return y; + } + return x; +} +#else +double sqrt(double x); +float sqrtf(float x); +#endif + +double atan(double x); +double copysign(double x, double y); +double cos(double x); +double floor(double x); +double frexp(double x, int *exp); +double ldexp(double x, int exp); +double modf(double x, double *intpart); +double sin(double x); +double tan(double x); +double acos(double x); +double asin(double x); +double atan2(double y, double x); +double fmod(double x, double y); +double log(double x); +double pow(double x, double y); +float tanf(float x); + +#ifdef __MWERKS__ +extern inline double fabs(double x) +{ + return __fabs(x); +} +#else +double fabs(double x); +#endif + +#endif diff --git a/include/dolphin/mtx.h b/include/dolphin/mtx.h index 9aba8f15..49dc1b7e 100644 --- a/include/dolphin/mtx.h +++ b/include/dolphin/mtx.h @@ -118,7 +118,7 @@ void PSMTXScaleApply(const Mtx src, Mtx dst, f32 xS, f32 yS, f32 zS); void PSMTXRotRad(Mtx m, char axis, f32 rad); void PSMTXRotTrig(Mtx m, char axis, f32 sinA, f32 cosA); -void PSMTXRotAxisRad(Mtx m, const Vec* axis, f32 rad); +void PSMTXRotAxisRad(register Mtx m, const Vec* axis, register f32 rad); #endif #ifdef MTX_USE_PS diff --git a/include/stdarg.h b/include/stdarg.h index 1ca0f853..e2cceee7 100644 --- a/include/stdarg.h +++ b/include/stdarg.h @@ -1,19 +1,39 @@ -#ifndef STDARG_H -#define STDARG_H +#ifndef _MSL_COMMON_STDARG_H +#define _MSL_COMMON_STDARG_H +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __MWERKS__ typedef struct { - char gpr; - char fpr; - char reserved[2]; - char* input_arg_area; - char* reg_save_area; + char gpr; + char fpr; + char reserved[2]; + char* input_arg_area; + char* reg_save_area; } __va_list[1]; typedef __va_list va_list; +#ifndef __MWERKS__ +extern void __builtin_va_info(va_list*); +#endif + void* __va_arg(va_list v_list, unsigned char type); -#define va_start(ap, fmt) ((void) fmt, __builtin_va_info(&ap)) -#define va_arg(ap, t) (*((t*) __va_arg(ap, _var_arg_typeof(t)))) -#define va_end(ap) (void) 0 +#define va_start(ap, fmt) ((void)fmt, __builtin_va_info(&ap)) +#define va_arg(ap, t) (*((t*)__va_arg(ap, _var_arg_typeof(t)))) +#define va_end(ap) (void)0 -#endif \ No newline at end of file +#else +typedef __builtin_va_list va_list; +#define va_start(v, l) __builtin_va_start(v, l) +#define va_end(v) __builtin_va_end(v) +#define va_arg(v, l) __builtin_va_arg(v, l) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _MSL_COMMON_STDARG_H */ diff --git a/include/stddef.h b/include/stddef.h index 5a133946..71816c2b 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -10,8 +10,13 @@ extern "C" { /* These break 1.2.5 */ //typedef __typeof__(sizeof(0)) size_t; //typedef __typeof__((char*)0 - (char*)0) ptrdiff_t; +#ifdef __INTELLISENSE__ +typedef unsigned int size_t; +typedef int ptrdiff_t; +#else typedef unsigned long size_t; typedef long ptrdiff_t; +#endif #ifndef NULL #define NULL 0L #endif @@ -20,4 +25,4 @@ typedef long ptrdiff_t; } #endif -#endif \ No newline at end of file +#endif diff --git a/include/string.h b/include/string.h index 583a906d..92f8f122 100644 --- a/include/string.h +++ b/include/string.h @@ -1,11 +1,22 @@ #ifndef _STRING_H_ #define _STRING_H_ -typedef unsigned long size_t; +#include "stddef.h" -void* memcpy(void* dst, const void* src, size_t n); -void* memset(void* dst, int val, size_t n); +#ifdef __MWERKS__ +__declspec(section ".init") void* memcpy(void* dest, const void* src, size_t n); +__declspec(section ".init") void __fill_mem(void* dest, int val, size_t count); +__declspec(section ".init") void* memset(void* dest, int val, size_t count); +#else +void* memcpy(void* dest, const void* src, size_t n); +void __fill_mem(void* dest, int val, size_t count); +void* memset(void* dest, int val, size_t count); +#endif +int memcmp(const void* lhs, const void* rhs, size_t count); +void* __memrchr(const void* ptr, int ch, size_t count); +void* memchr(const void* ptr, int ch, size_t count); +void* memmove(void* dst, const void* src, size_t n); char* strrchr(const char* str, int c); char* strchr(const char* str, int c); int strncmp(const char* str1, const char* str2, size_t n); @@ -15,4 +26,4 @@ char* strncpy(char* dst, const char* src, size_t n); char* strcpy(char* dst, const char* src); size_t strlen(const char* str); -#endif \ No newline at end of file +#endif diff --git a/src/MSL_C.PPCEABI.bare.H/abort_exit.c b/src/MSL_C.PPCEABI.bare.H/abort_exit.c new file mode 100644 index 00000000..1c9ca4d2 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/abort_exit.c @@ -0,0 +1,55 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/abort_exit.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/critical_regions.h" +#include "stddef.h" +#include "PowerPC_EABI_Support/Runtime/NMWException.h" + +void _ExitProcess(); + +extern void (*_dtors[])(void); + +int __aborting = 0; + +static void (*atexit_funcs[64])(void); +static int atexit_curr_func = 0; + +static void (*__atexit_funcs[64])(void); +static int __atexit_curr_func = 0; + +void (*__stdio_exit)(void) = 0; +void (*__console_exit)(void) = 0; + +void abort(void) +{ + // TODO +} + +void exit(int status) +{ + int i; + void (**dtor)(void); + + if (!__aborting) { + __destroy_global_chain(); + + dtor = _dtors; + while (*dtor != NULL) { + (*dtor)(); + dtor++; + } + + if (__stdio_exit != NULL) { + __stdio_exit(); + __stdio_exit = NULL; + } + } + + while (__atexit_curr_func > 0) + __atexit_funcs[--__atexit_curr_func](); + + if (__console_exit != NULL) { + __console_exit(); + __console_exit = NULL; + } + + _ExitProcess(); +} diff --git a/src/MSL_C.PPCEABI.bare.H/ansi_files.c b/src/MSL_C.PPCEABI.bare.H/ansi_files.c new file mode 100644 index 00000000..f0113bf4 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/ansi_files.c @@ -0,0 +1,95 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/file_io.h" + +extern files __files = { + { + 0, + 0, + 1, + 0, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + { 0, 0 }, + { 0, 0 }, + 0, + (unsigned char*)&__files._stdin.char_buffer, + 1, + (unsigned char*)&__files._stdin.char_buffer, + 0, + 0, + 0, + 0, + NULL, + __read_console, + __write_console, + __close_console, + NULL, + }, + { + 0, + 0, + 2, + 0, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + { 0, 0 }, + { 0, 0 }, + 0, + (unsigned char*)&__files._stdout.char_buffer, + 1, + (unsigned char*)&__files._stdout.char_buffer, + 0, + 0, + 0, + 0, + NULL, + __read_console, + __write_console, + __close_console, + NULL, + }, + { + 0, + 0, + 2, + 0, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + { 0, 0 }, + { 0, 0 }, + 0, + (unsigned char*)&__files._stderr.char_buffer, + 1, + (unsigned char*)&__files._stderr.char_buffer, + 0, + 0, + 0, + 0, + NULL, + __read_console, + __write_console, + __close_console, + NULL, + }, +}; diff --git a/src/MSL_C.PPCEABI.bare.H/buffer_io.c b/src/MSL_C.PPCEABI.bare.H/buffer_io.c new file mode 100644 index 00000000..5657680d --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/buffer_io.c @@ -0,0 +1,41 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" + +void __prep_buffer(FILE* file) +{ + file->buffer_ptr = file->buffer; + file->buffer_length = file->buffer_size; + file->buffer_length -= file->position & file->buffer_alignment; + file->buffer_position = file->position; +} + +void __convert_from_newlines(unsigned char* p, size_t* n) { } + +int __flush_buffer(FILE* file, size_t* bytes_flushed) +{ + size_t buffer_len; + int ioresult; + + buffer_len = file->buffer_ptr - file->buffer; + + if (buffer_len) { + file->buffer_length = buffer_len; + + if (!file->file_mode.binary_io) + __convert_from_newlines(file->buffer, &file->buffer_length); + + ioresult = (*file->write_fn)(file->handle, file->buffer, + &file->buffer_length, file->idle_fn); + + if (bytes_flushed) + *bytes_flushed = file->buffer_length; + + if (ioresult) + return ioresult; + + file->position += file->buffer_length; + } + + __prep_buffer(file); + + return __no_io_error; +} diff --git a/src/MSL_C.PPCEABI.bare.H/ctype.c b/src/MSL_C.PPCEABI.bare.H/ctype.c new file mode 100644 index 00000000..e0a797cb --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/ctype.c @@ -0,0 +1,85 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ctype.h" + +#define ctrl __control_char +#define motn __motion_char +#define spac __space_char +#define punc __punctuation +#define digi __digit +#define hexd __hex_digit +#define lowc __lower_case +#define uppc __upper_case +#define dhex (hexd | digi) +#define uhex (hexd | uppc) +#define lhex (hexd | lowc) + +const unsigned char __ctype_map[256] = { + // clang-format off + ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, motn, motn, motn, motn, motn, ctrl, ctrl, + ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, + spac, punc, punc, punc, punc, punc, punc, punc, punc, punc, punc, punc, punc, punc, punc, punc, + dhex, dhex, dhex, dhex, dhex, dhex, dhex, dhex, dhex, dhex, punc, punc, punc, punc, punc, punc, + punc, uhex, uhex, uhex, uhex, uhex, uhex, uppc, uppc, uppc, uppc, uppc, uppc, uppc, uppc, uppc, + uppc, uppc, uppc, uppc, uppc, uppc, uppc, uppc, uppc, uppc, uppc, punc, punc, punc, punc, punc, + punc, lhex, lhex, lhex, lhex, lhex, lhex, lowc, lowc, lowc, lowc, lowc, lowc, lowc, lowc, lowc, + lowc, lowc, lowc, lowc, lowc, lowc, lowc, lowc, lowc, lowc, lowc, punc, punc, punc, punc, ctrl, + // clang-format on +}; + +const unsigned char __lower_map[256] = { + // clang-format off + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, + ' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', + '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\\', ']', '^', '_', + '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 0x7F, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, + 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, + 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, + 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, + 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, + // clang-format on +}; + +const unsigned char __upper_map[256] = { + // clang-format off + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, + ' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', + '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', + '`', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '{', '|', '}', '~', 0x7F, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, + 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, + 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, + 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, + 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, + // clang-format on +}; + +int tolower(int __c) +{ + if (__c == -1) + return -1; + + return __lower_map[__c & 0xff]; +} + +int toupper(int __c) +{ + + if (__c == -1) + return -1; + + return __upper_map[__c & 0xff]; +} diff --git a/src/MSL_C.PPCEABI.bare.H/direct_io.c b/src/MSL_C.PPCEABI.bare.H/direct_io.c new file mode 100644 index 00000000..51184220 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/direct_io.c @@ -0,0 +1,114 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/direct_io.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/buffer_io.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/misc_io.h" +#include "string.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/wchar_io.h" + +size_t fwrite(const void* buffer, size_t size, size_t count, FILE* stream) +{ + unsigned char* write_ptr; + size_t num_bytes, bytes_to_go, bytes_written; + int ioresult, always_buffer; + + if (fwide(stream, 0) == 0) + fwide(stream, -1); + + bytes_to_go = size * count; + + if (!bytes_to_go || stream->file_state.error + || stream->file_mode.file_kind == __closed_file) + return 0; + + if ((int)stream->file_mode.file_kind == __console_file) + __stdio_atexit(); + + always_buffer = !stream->file_mode.binary_io + || (int)stream->file_mode.file_kind == __string_file + || stream->file_mode.buffer_mode == _IOFBF + || stream->file_mode.buffer_mode == _IOLBF; + + if (stream->file_state.io_state == __neutral) { + if (stream->file_mode.io_mode & __write) { + stream->file_state.io_state = __writing; + + __prep_buffer(stream); + } + } + + if (stream->file_state.io_state != __writing) { + set_error(stream); + return 0; + } + + write_ptr = (unsigned char*)buffer; + bytes_written = 0; + + if (bytes_to_go + && (stream->buffer_ptr != stream->buffer || always_buffer)) { + stream->buffer_length + = stream->buffer_size - (stream->buffer_ptr - stream->buffer); + + do { + unsigned char* newline = NULL; + + num_bytes = stream->buffer_length; + + if (num_bytes > bytes_to_go) + num_bytes = bytes_to_go; + + if (num_bytes) { + memcpy(stream->buffer_ptr, write_ptr, num_bytes); + + write_ptr += num_bytes; + bytes_written += num_bytes; + bytes_to_go -= num_bytes; + + stream->buffer_ptr += num_bytes; + stream->buffer_length -= num_bytes; + } + + if (!stream->buffer_length + && (int)stream->file_mode.file_kind == __string_file) { + bytes_written += bytes_to_go; + break; + } + + if (!stream->buffer_length || newline != NULL + || (stream->file_mode.buffer_mode == _IONBF)) { + ioresult = __flush_buffer(stream, NULL); + + if (ioresult) { + set_error(stream); + bytes_to_go = 0; + break; + } + } + } while (bytes_to_go && always_buffer); + } + + if (bytes_to_go && !always_buffer) { + unsigned char* save_buffer = stream->buffer; + size_t save_size = stream->buffer_size; + + stream->buffer = write_ptr; + stream->buffer_size = bytes_to_go; + stream->buffer_ptr = write_ptr + bytes_to_go; + + if (__flush_buffer(stream, &num_bytes) != __no_io_error) + set_error(stream); + + bytes_written += num_bytes; + + stream->buffer = save_buffer; + stream->buffer_size = save_size; + + __prep_buffer(stream); + + stream->buffer_length = 0; + } + + if (stream->file_mode.buffer_mode != _IOFBF) + stream->buffer_length = 0; + + return ((bytes_written + size - 1) / size); +} diff --git a/src/MSL_C.PPCEABI.bare.H/e_asin.c b/src/MSL_C.PPCEABI.bare.H/e_asin.c new file mode 100644 index 00000000..bc5754f4 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/e_asin.c @@ -0,0 +1,3 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common_Embedded/Math/fdlibm.h" + +double fabs__Fd(double v) { return __fabs(v); } diff --git a/src/MSL_C.PPCEABI.bare.H/e_atan2.c b/src/MSL_C.PPCEABI.bare.H/e_atan2.c new file mode 100644 index 00000000..43b99afd --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/e_atan2.c @@ -0,0 +1,145 @@ + +/* @(#)e_atan2.c 1.3 95/01/18 */ +/** + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +/* __ieee754_atan2(y,x) + * Method : + * 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x). + * 2. Reduce x to positive by (if x and y are unexceptional): + * ARG (x+iy) = arctan(y/x) ... if x > 0, + * ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0, + * + * Special cases: + * + * ATAN2((anything), NaN ) is NaN; + * ATAN2(NAN , (anything) ) is NaN; + * ATAN2(+-0, +(anything but NaN)) is +-0 ; + * ATAN2(+-0, -(anything but NaN)) is +-pi ; + * ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2; + * ATAN2(+-(anything but INF and NaN), +INF) is +-0 ; + * ATAN2(+-(anything but INF and NaN), -INF) is +-pi; + * ATAN2(+-INF,+INF ) is +-pi/4 ; + * ATAN2(+-INF,-INF ) is +-3pi/4; + * ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2; + * + * Constants: + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + */ + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common_Embedded/Math/fdlibm.h" + +#ifdef __STDC__ +static const double +#else +static double +#endif + tiny + = 1.0e-300, + zero = 0.0, pi_o_4 = 7.8539816339744827900E-01, /* 0x3FE921FB, 0x54442D18 */ + pi_o_2 = 1.5707963267948965580E+00, /* 0x3FF921FB, 0x54442D18 */ + pi = 3.1415926535897931160E+00, /* 0x400921FB, 0x54442D18 */ + pi_lo = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */ + +#ifdef __STDC__ +double __ieee754_atan2(double y, double x) +#else +double __ieee754_atan2(y, x) +double y, x; +#endif +{ + double z; + int k, m, hx, hy, ix, iy; + unsigned lx, ly; + + hx = __HI(x); + ix = hx & 0x7fffffff; + lx = __LO(x); + hy = __HI(y); + iy = hy & 0x7fffffff; + ly = __LO(y); + if (((ix | ((lx | -lx) >> 31)) > 0x7ff00000) + || ((iy | ((ly | -ly) >> 31)) > 0x7ff00000)) /* x or y is NaN */ + return x + y; + if ((hx - 0x3ff00000 | lx) == 0) + return atan(y); /* x=1.0 */ + m = ((hy >> 31) & 1) | ((hx >> 30) & 2); /* 2*sign(x)+sign(y) */ + + /* when y = 0 */ + if ((iy | ly) == 0) { + switch (m) { + case 0: + case 1: + return y; /* atan(+-0,+anything)=+-0 */ + case 2: + return pi + tiny; /* atan(+0,-anything) = pi */ + case 3: + return -pi - tiny; /* atan(-0,-anything) =-pi */ + } + } + /* when x = 0 */ + if ((ix | lx) == 0) + return (hy < 0) ? -pi_o_2 - tiny : pi_o_2 + tiny; + + /* when x is INF */ + if (ix == 0x7ff00000) { + if (iy == 0x7ff00000) { + switch (m) { + case 0: + return pi_o_4 + tiny; /* atan(+INF,+INF) */ + case 1: + return -pi_o_4 - tiny; /* atan(-INF,+INF) */ + case 2: + return 3.0 * pi_o_4 + tiny; /*atan(+INF,-INF)*/ + case 3: + return -3.0 * pi_o_4 - tiny; /*atan(-INF,-INF)*/ + } + } else { + switch (m) { + case 0: + return zero; /* atan(+...,+INF) */ + case 1: + return -zero; /* atan(-...,+INF) */ + case 2: + return pi + tiny; /* atan(+...,-INF) */ + case 3: + return -pi - tiny; /* atan(-...,-INF) */ + } + } + } + /* when y is INF */ + if (iy == 0x7ff00000) + return (hy < 0) ? -pi_o_2 - tiny : pi_o_2 + tiny; + + /* compute y/x */ + k = (iy - ix) >> 20; + if (k > 60) + z = pi_o_2 + 0.5 * pi_lo; /* |y/x| > 2**60 */ + else if (hx < 0 && k < -60) + z = 0.0; /* |y|/x < -2**60 */ + else + z = atan(fabs__Fd(y / x)); /* safe to do y/x */ + switch (m) { + case 0: + return z; /* atan(+,+) */ + case 1: + __HI(z) ^= 0x80000000; + return z; /* atan(-,+) */ + case 2: + return pi - (z - pi_lo); /* atan(+,-) */ + default: /* case 3 */ + return (z - pi_lo) - pi; /* atan(-,-) */ + } +} diff --git a/src/MSL_C.PPCEABI.bare.H/errno.c b/src/MSL_C.PPCEABI.bare.H/errno.c new file mode 100644 index 00000000..fb0a2b41 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/errno.c @@ -0,0 +1,3 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/errno.h" + +int errno; diff --git a/src/MSL_C.PPCEABI.bare.H/float.c b/src/MSL_C.PPCEABI.bare.H/float.c new file mode 100644 index 00000000..f07b2812 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/float.c @@ -0,0 +1,5 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/float.h" + +unsigned long __float_nan[] = { 0x7FFFFFFF }; + +unsigned long __float_huge[] = { 0x7F800000 }; diff --git a/src/MSL_C.PPCEABI.bare.H/mbstring.c b/src/MSL_C.PPCEABI.bare.H/mbstring.c new file mode 100644 index 00000000..fa77c660 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/mbstring.c @@ -0,0 +1,18 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mbstring.h" + +size_t wcstombs(char* s, const wchar_t* pwcs, size_t n) +{ + wchar_t next; + size_t chars_written; + int i; + + chars_written = 0; + for (i = 0; i < n; ++i) { + next = *pwcs++; + *s++ = (char)next; + if ((char)next == '\0') + break; + ++chars_written; + } + return chars_written; +} diff --git a/src/MSL_C.PPCEABI.bare.H/mem.c b/src/MSL_C.PPCEABI.bare.H/mem.c new file mode 100644 index 00000000..63a4434f --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/mem.c @@ -0,0 +1,75 @@ +#include "string.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mem_funcs.h" + +void* memmove(void* dst, const void* src, size_t n) +{ + unsigned char* csrc; + unsigned char* cdst; + + int reverse = (unsigned int)src < (unsigned int)dst; + + if (n >= 32) { + if (((unsigned int)dst ^ (unsigned int)src) & 3) { + if (!reverse) { + __copy_longs_unaligned(dst, src, n); + } else { + __copy_longs_rev_unaligned(dst, src, n); + } + } else { + if (!reverse) { + __copy_longs_aligned(dst, src, n); + } else { + __copy_longs_rev_aligned(dst, src, n); + } + } + + return dst; + } else { + if (!reverse) { + csrc = ((unsigned char*)src) - 1; + cdst = ((unsigned char*)dst) - 1; + n++; + + while (--n > 0) { + *++cdst = *++csrc; + } + } else { + csrc = (unsigned char*)src + n; + cdst = (unsigned char*)dst + n; + n++; + + while (--n > 0) { + *--cdst = *--csrc; + } + } + } + + return dst; +} + +void* memchr(const void* ptr, int ch, size_t count) +{ + const unsigned char* p; + + unsigned long v = (ch & 0xff); + + for (p = (unsigned char*)ptr - 1, count++; --count;) + if ((*++p & 0xff) == v) + return (void*)p; + + return NULL; +} + +int memcmp(const void* lhs, const void* rhs, size_t count) +{ + const unsigned char* p1; + const unsigned char* p2; + + for (p1 = (const unsigned char*)lhs - 1, p2 = (const unsigned char*)rhs - 1, + count++; + --count;) + if (*++p1 != *++p2) + return ((*p1 < *p2) ? -1 : +1); + + return 0; +} diff --git a/src/MSL_C.PPCEABI.bare.H/mem_funcs.c b/src/MSL_C.PPCEABI.bare.H/mem_funcs.c new file mode 100644 index 00000000..a22984c4 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/mem_funcs.c @@ -0,0 +1,221 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mem_funcs.h" + +#define cps ((unsigned char*)src) +#define cpd ((unsigned char*)dst) +#define lps ((unsigned long*)src) +#define lpd ((unsigned long*)dst) +#define deref_auto_inc(p) *++(p) + +void __copy_longs_aligned(void* dst, const void* src, size_t n) +{ + unsigned long i; + + i = (-(unsigned long)dst) & 3; + + cps = ((unsigned char*)src) - 1; + cpd = ((unsigned char*)dst) - 1; + + if (i) { + n -= i; + + do + deref_auto_inc(cpd) = deref_auto_inc(cps); + while (--i); + } + + lps = ((unsigned long*)(cps + 1)) - 1; + lpd = ((unsigned long*)(cpd + 1)) - 1; + + i = n >> 5; + + if (i) + do { + deref_auto_inc(lpd) = deref_auto_inc(lps); + deref_auto_inc(lpd) = deref_auto_inc(lps); + deref_auto_inc(lpd) = deref_auto_inc(lps); + deref_auto_inc(lpd) = deref_auto_inc(lps); + deref_auto_inc(lpd) = deref_auto_inc(lps); + deref_auto_inc(lpd) = deref_auto_inc(lps); + deref_auto_inc(lpd) = deref_auto_inc(lps); + deref_auto_inc(lpd) = deref_auto_inc(lps); + } while (--i); + + i = (n & 31) >> 2; + + if (i) + do + deref_auto_inc(lpd) = deref_auto_inc(lps); + while (--i); + + cps = ((unsigned char*)(lps + 1)) - 1; + cpd = ((unsigned char*)(lpd + 1)) - 1; + + n &= 3; + + if (n) + do + deref_auto_inc(cpd) = deref_auto_inc(cps); + while (--n); + + return; +} + +void __copy_longs_rev_aligned(void* dst, const void* src, size_t n) +{ + unsigned long i; + + cps = ((unsigned char*)src) + n; + cpd = ((unsigned char*)dst) + n; + + i = ((unsigned long)cpd) & 3; + + if (i) { + n -= i; + + do + *--cpd = *--cps; + while (--i); + } + + i = n >> 5; + + if (i) + do { + *--lpd = *--lps; + *--lpd = *--lps; + *--lpd = *--lps; + *--lpd = *--lps; + *--lpd = *--lps; + *--lpd = *--lps; + *--lpd = *--lps; + *--lpd = *--lps; + } while (--i); + + i = (n & 31) >> 2; + + if (i) + do + *--lpd = *--lps; + while (--i); + + n &= 3; + + if (n) + do + *--cpd = *--cps; + while (--n); + + return; +} + +void __copy_longs_unaligned(void* dst, const void* src, size_t n) +{ + unsigned long i, v1, v2; + unsigned int src_offset, left_shift, right_shift; + + i = (-(unsigned long)dst) & 3; + + cps = ((unsigned char*)src) - 1; + cpd = ((unsigned char*)dst) - 1; + + if (i) { + n -= i; + + do + deref_auto_inc(cpd) = deref_auto_inc(cps); + while (--i); + } + + src_offset = ((unsigned int)(cps + 1)) & 3; + + left_shift = src_offset << 3; + right_shift = 32 - left_shift; + + cps -= src_offset; + + lps = ((unsigned long*)(cps + 1)) - 1; + lpd = ((unsigned long*)(cpd + 1)) - 1; + + i = n >> 3; + + v1 = deref_auto_inc(lps); + + do { + v2 = deref_auto_inc(lps); + deref_auto_inc(lpd) = (v1 << left_shift) | (v2 >> right_shift); + v1 = deref_auto_inc(lps); + deref_auto_inc(lpd) = (v2 << left_shift) | (v1 >> right_shift); + } while (--i); + + if (n & 4) { + v2 = deref_auto_inc(lps); + deref_auto_inc(lpd) = (v1 << left_shift) | (v2 >> right_shift); + } + + cps = ((unsigned char*)(lps + 1)) - 1; + cpd = ((unsigned char*)(lpd + 1)) - 1; + + n &= 3; + + if (n) { + cps -= 4 - src_offset; + do + deref_auto_inc(cpd) = deref_auto_inc(cps); + while (--n); + } + + return; +} + +void __copy_longs_rev_unaligned(void* dst, const void* src, size_t n) +{ + unsigned long i, v1, v2; + unsigned int src_offset, left_shift, right_shift; + + cps = ((unsigned char*)src) + n; + cpd = ((unsigned char*)dst) + n; + + i = ((unsigned long)cpd) & 3; + + if (i) { + n -= i; + + do + *--cpd = *--cps; + while (--i); + } + + src_offset = ((unsigned int)cps) & 3; + + left_shift = src_offset << 3; + right_shift = 32 - left_shift; + + cps += 4 - src_offset; + + i = n >> 3; + + v1 = *--lps; + + do { + v2 = *--lps; + *--lpd = (v2 << left_shift) | (v1 >> right_shift); + v1 = *--lps; + *--lpd = (v1 << left_shift) | (v2 >> right_shift); + } while (--i); + + if (n & 4) { + v2 = *--lps; + *--lpd = (v2 << left_shift) | (v1 >> right_shift); + } + + n &= 3; + + if (n) { + cps += src_offset; + do + *--cpd = *--cps; + while (--n); + } + + return; +} diff --git a/src/MSL_C.PPCEABI.bare.H/misc_io.c b/src/MSL_C.PPCEABI.bare.H/misc_io.c new file mode 100644 index 00000000..2b6c9913 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/misc_io.c @@ -0,0 +1 @@ +void __stdio_atexit(void) { } diff --git a/src/MSL_C.PPCEABI.bare.H/printf.c b/src/MSL_C.PPCEABI.bare.H/printf.c new file mode 100644 index 00000000..21d248da --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/printf.c @@ -0,0 +1,1076 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/printf.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_fp.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/direct_io.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ctype.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/scanf.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdio.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdlib.h" +#include "string.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/wchar_io.h" +#include "stdarg.h" + +extern void __num2dec(const decform*, double, decimal*); + +#define TARGET_FLOAT_BITS 64 +#define TARGET_FLOAT_BYTES (TARGET_FLOAT_BITS / 8) +#define TARGET_FLOAT_MAX_EXP LDBL_MAX_EXP +#define TARGET_FLOAT_MANT_DIG LDBL_MANT_DIG +#define TARGET_FLOAT_IMPLICIT_J_BIT 1 +#define TARGET_FLOAT_MANT_BITS \ + (TARGET_FLOAT_MANT_DIG - TARGET_FLOAT_IMPLICIT_J_BIT) +#define TARGET_FLOAT_EXP_BITS (TARGET_FLOAT_BITS - TARGET_FLOAT_MANT_BITS - 1) + +enum justification_options { + left_justification, + right_justification, + zero_fill +}; + +enum sign_options { only_minus, sign_always, space_holder }; + +enum argument_options { + normal_argument, + char_argument, + short_argument, + long_argument, + long_long_argument, + long_double_argument, + wchar_argument +}; + +typedef struct { + unsigned char justification_options; + unsigned char sign_options; + unsigned char precision_specified; + unsigned char alternate_form; + unsigned char argument_options; + unsigned char conversion_char; + int field_width; + int precision; +} print_format; + +static const char* parse_format(const char* format_string, va_list* arg, + print_format* format) +{ + print_format f; + const char* s = format_string; + int c; + int flag_found; + f.justification_options = right_justification; + f.sign_options = only_minus; + f.precision_specified = 0; + f.alternate_form = 0; + f.argument_options = normal_argument; + f.field_width = 0; + f.precision = 0; + + if ((c = *++s) == '%') { + f.conversion_char = c; + *format = f; + return ((const char*)s + 1); + } + + for (;;) { + flag_found = 1; + + switch (c) { + case '-': + f.justification_options = left_justification; + break; + case '+': + f.sign_options = sign_always; + break; + case ' ': + if (f.sign_options != sign_always) { + f.sign_options = space_holder; + } + break; + case '#': + f.alternate_form = 1; + break; + case '0': + if (f.justification_options != left_justification) { + f.justification_options = zero_fill; + } + break; + default: + flag_found = 0; + break; + } + + if (flag_found) { + c = *++s; + } else { + break; + } + } + + if (c == '*') { + if ((f.field_width = va_arg(*arg, int)) < 0) { + f.justification_options = left_justification; + f.field_width = -f.field_width; + } + + c = *++s; + } else { + while (isdigit(c)) { + f.field_width = (f.field_width * 10) + (c - '0'); + c = *++s; + } + } + + if (f.field_width > 509) { + f.conversion_char = 0xFF; + *format = f; + return ((const char*)s + 1); + } + + if (c == '.') { + f.precision_specified = 1; + + if ((c = *++s) == '*') { + if ((f.precision = va_arg(*arg, int)) < 0) { + f.precision_specified = 0; + } + + c = *++s; + } else { + while (isdigit(c)) { + f.precision = (f.precision * 10) + (c - '0'); + c = *++s; + } + } + } + + flag_found = 1; + + switch (c) { + case 'h': + f.argument_options = short_argument; + + if (s[1] == 'h') { + f.argument_options = char_argument; + c = *++s; + } + + break; + + case 'l': + f.argument_options = long_argument; + + if (s[1] == 'l') { + f.argument_options = long_long_argument; + c = *++s; + } + + break; + + case 'L': + f.argument_options = long_double_argument; + break; + default: + flag_found = 0; + break; + } + + if (flag_found) { + c = *++s; + } + + f.conversion_char = c; + + switch (c) { + case 'd': + case 'i': + case 'u': + case 'o': + case 'x': + case 'X': + if (f.argument_options == long_double_argument) { + f.conversion_char = 0xFF; + break; + } + + if (!f.precision_specified) { + f.precision = 1; + } else if (f.justification_options == zero_fill) { + f.justification_options = right_justification; + } + break; + + case 'f': + if (f.argument_options == short_argument + || f.argument_options == long_long_argument) { + f.conversion_char = 0xFF; + break; + } + + if (!f.precision_specified) { + f.precision = 6; + } + break; + + case 'g': + case 'G': + if (!f.precision) { + f.precision = 1; + } + + case 'e': + case 'E': + if (f.argument_options == short_argument + || f.argument_options == long_long_argument + || f.argument_options == char_argument) { + f.conversion_char = 0xFF; + break; + } + + if (!f.precision_specified) { + f.precision = 6; + } + break; + + case 'p': + f.conversion_char = 'x'; + f.alternate_form = 1; + f.argument_options = long_argument; + f.precision = 8; + break; + + case 'c': + if (f.argument_options == long_argument) { + f.argument_options = wchar_argument; + } else { + if (f.precision_specified + || f.argument_options != normal_argument) { + f.conversion_char = 0xFF; + } + } + + break; + + case 's': + if (f.argument_options == long_argument) { + f.argument_options = wchar_argument; + } else { + if (f.argument_options != normal_argument) { + f.conversion_char = 0xFF; + } + } + + break; + + case 'n': + if (f.argument_options == long_double_argument) { + f.conversion_char = 0xFF; + } + + break; + + default: + f.conversion_char = 0xFF; + break; + } + + *format = f; + return ((const char*)s + 1); +} + +static char* long2str(signed long num, char* buff, print_format* format) +{ + unsigned long unsigned_num, base; + char* p; + int n, digits; + int minus = 0; + unsigned_num = num; + minus = 0; + + p = buff; + *--p = 0; + digits = 0; + + if (!num && !format->precision + && !(format->alternate_form && format->conversion_char == 'o')) { + return p; + } + + switch (format->conversion_char) { + case 'd': + case 'i': + base = 10; + + if (num < 0) { + unsigned_num = -unsigned_num; + minus = 1; + } + break; + + case 'o': + base = 8; + format->sign_options = only_minus; + break; + + case 'u': + base = 10; + format->sign_options = only_minus; + break; + + case 'x': + case 'X': + base = 16; + format->sign_options = only_minus; + break; + } + + do { + n = unsigned_num % base; + unsigned_num /= base; + + if (n < 10) { + n += '0'; + } else { + n -= 10; + + if (format->conversion_char == 'x') { + n += 'a'; + } else { + n += 'A'; + } + } + + *--p = n; + ++digits; + } while (unsigned_num != 0); + + if (base == 8 && format->alternate_form && *p != '0') { + *--p = '0'; + ++digits; + } + + if (format->justification_options == zero_fill) { + format->precision = format->field_width; + + if (minus || format->sign_options != only_minus) + --format->precision; + + if (base == 16 && format->alternate_form) + format->precision -= 2; + } + + if (buff - p + format->precision > 509) + return (0); + + while (digits < format->precision) { + *--p = '0'; + ++digits; + } + + if (base == 16 && format->alternate_form) { + *--p = format->conversion_char; + *--p = '0'; + } + + if (minus) { + *--p = '-'; + } else if (format->sign_options == sign_always) { + *--p = '+'; + } else if (format->sign_options == space_holder) { + *--p = ' '; + } + + return p; +} + +static char* longlong2str(signed long long num, char* pBuf, print_format* fmt) +{ + unsigned long long unsigned_num, base; + char* p; + int n, digits; + int minus = 0; + unsigned_num = num; + minus = 0; + p = pBuf; + *--p = 0; + digits = 0; + + if (!num && !fmt->precision + && !(fmt->alternate_form && fmt->conversion_char == 'o')) { + return p; + } + + switch (fmt->conversion_char) { + case 'd': + case 'i': + base = 10; + + if (num < 0) { + unsigned_num = -unsigned_num; + minus = 1; + } + break; + case 'o': + base = 8; + fmt->sign_options = only_minus; + break; + case 'u': + base = 10; + fmt->sign_options = only_minus; + break; + case 'x': + case 'X': + base = 16; + fmt->sign_options = only_minus; + break; + } + + do { + n = unsigned_num % base; + unsigned_num /= base; + + if (n < 10) { + n += '0'; + } else { + n -= 10; + if (fmt->conversion_char == 'x') { + n += 'a'; + } else { + n += 'A'; + } + } + + *--p = n; + ++digits; + } while (unsigned_num != 0); + + if (base == 8 && fmt->alternate_form && *p != '0') { + *--p = '0'; + ++digits; + } + + if (fmt->justification_options == zero_fill) { + fmt->precision = fmt->field_width; + + if (minus || fmt->sign_options != only_minus) { + --fmt->precision; + } + + if (base == 16 && fmt->alternate_form) { + fmt->precision -= 2; + } + } + + if (pBuf - p + fmt->precision > 509) { + return 0; + } + + while (digits < fmt->precision) { + *--p = '0'; + ++digits; + } + + if (base == 16 && fmt->alternate_form) { + *--p = fmt->conversion_char; + *--p = '0'; + } + + if (minus) { + *--p = '-'; + } else if (fmt->sign_options == sign_always) { + *--p = '+'; + } else if (fmt->sign_options == space_holder) { + *--p = ' '; + } + + return p; +} + +static void round_decimal(decimal* dec, int new_length) +{ + char c; + char* p; + int carry; + + if (new_length < 0) { + return_zero: + dec->sign = 0; + dec->exp = 0; + dec->sig.length = 1; + *dec->sig.text = '0'; + return; + } + + if (new_length >= dec->sig.length) { + return; + } + + p = (char*)dec->sig.text + new_length + 1; + c = *--p - '0'; + + if (c == 5) { + char* q = &((char*)dec->sig.text)[dec->sig.length]; + + while (--q > p && *q == '0') + ; + carry = (q == p) ? p[-1] & 1 : 1; + } else { + carry = (c > 5); + } + + while (new_length != 0) { + c = *--p - '0' + carry; + + if ((carry = (c > 9)) != 0 || c == 0) { + --new_length; + } else { + *p = c + '0'; + break; + } + } + + if (carry != 0) { + dec->exp += 1; + dec->sig.length = 1; + *dec->sig.text = '1'; + return; + } else if (new_length == 0) { + goto return_zero; + } + + dec->sig.length = new_length; +} + +static char* float2str(va_list arg, char* buff, print_format* format, + int vecIndex) +{ + decimal dec; + decform form; + char* p; + char* q; + int n, digits, sign; + int int_digits, frac_digits; + long double num; + + if (format->argument_options == long_double_argument) { + num = va_arg(arg, long double); + } else { + num = va_arg(arg, double); + } + + if (format->precision > 509) { + return 0; + } + + form.style = 0; + form.digits = 0x20; + __num2dec(&form, num, &dec); + p = (char*)dec.sig.text + dec.sig.length; + + while (dec.sig.length > 1 && *--p == '0') { + --dec.sig.length; + ++dec.exp; + } + + switch (*dec.sig.text) { + case '0': + dec.exp = 0; + break; + case 'I': + if (num < 0) { + p = buff - 5; + strcpy(p, "-Inf"); + } else { + p = buff - 4; + strcpy(p, "Inf"); + } + + return p; + + case 'N': + p = buff - 4; + strcpy(p, "NaN"); + return p; + } + + dec.exp += dec.sig.length - 1; + p = buff; + *--p = 0; + + switch (format->conversion_char) { + case 'g': + case 'G': + + if (dec.sig.length > format->precision) { + round_decimal(&dec, format->precision); + } + + if (dec.exp < -4 || dec.exp >= format->precision) { + if (format->alternate_form) { + --format->precision; + } else { + format->precision = dec.sig.length - 1; + } + + if (format->conversion_char == 'g') { + format->conversion_char = 'e'; + } else { + format->conversion_char = 'E'; + } + + goto e_format; + } + + if (format->alternate_form) { + format->precision -= dec.exp + 1; + } else { + if ((format->precision = dec.sig.length - (dec.exp + 1)) < 0) { + format->precision = 0; + } + } + + goto f_format; + + case 'e': + case 'E': + e_format: + + if (dec.sig.length > format->precision + 1) { + round_decimal(&dec, format->precision + 1); + } + + n = dec.exp; + sign = '+'; + + if (n < 0) { + n = -n; + sign = '-'; + } + + for (digits = 0; n || digits < 2; ++digits) { + *--p = n % 10 + '0'; + n /= 10; + } + + *--p = sign; + *--p = format->conversion_char; + + if (buff - p + format->precision > 509) { + return 0; + } + + if (dec.sig.length < format->precision + 1) { + for (n = format->precision + 1 - dec.sig.length + 1; --n;) { + *--p = '0'; + } + } + + for (n = dec.sig.length, q = (char*)dec.sig.text + dec.sig.length; + --n;) { + *--p = *--q; + } + + if (format->precision || format->alternate_form) { + *--p = '.'; + } + + *--p = *dec.sig.text; + + if (dec.sign) + *--p = '-'; + else if (format->sign_options == sign_always) + *--p = '+'; + else if (format->sign_options == space_holder) + *--p = ' '; + + break; + + case 'f': + f_format: + + if ((frac_digits = -dec.exp + dec.sig.length - 1) < 0) + frac_digits = 0; + + if (frac_digits > format->precision) { + round_decimal(&dec, + dec.sig.length - (frac_digits - format->precision)); + + if ((frac_digits = -dec.exp + dec.sig.length - 1) < 0) + frac_digits = 0; + } + + if ((int_digits = dec.exp + 1) < 0) + int_digits = 0; + + if (int_digits + frac_digits > 509) + return 0; + + q = (char*)dec.sig.text + dec.sig.length; + + for (digits = 0; digits < (format->precision - frac_digits); ++digits) + *--p = '0'; + + for (digits = 0; digits < frac_digits && digits < dec.sig.length; + ++digits) + *--p = *--q; + + for (; digits < frac_digits; ++digits) + *--p = '0'; + + if (format->precision || format->alternate_form) + *--p = '.'; + + if (int_digits) { + for (digits = 0; digits < int_digits - dec.sig.length; ++digits) { + *--p = '0'; + } + + for (; digits < int_digits; ++digits) { + *--p = *--q; + } + } else { + *--p = '0'; + } + + if (dec.sign) { + *--p = '-'; + } else if (format->sign_options == sign_always) { + *--p = '+'; + } else if (format->sign_options == space_holder) { + *--p = ' '; + } + + break; + } + + return p; +} + +static int __pformatter(void* (*WriteProc)(void*, const char*, size_t), + void* WriteProcArg, const char* format_str, va_list arg) +{ + int num_chars, chars_written, field_width; + const char* format_ptr; + const char* curr_format; + print_format format; + signed long long_num; + signed long long long_long_num; + char buff[512]; + char* buff_ptr; + char* string_end; + char fill_char = ' '; + + format_ptr = format_str; + chars_written = 0; + + while (*format_ptr) { + if (!(curr_format = strchr(format_ptr, '%'))) { + num_chars = strlen(format_ptr); + chars_written += num_chars; + + if (num_chars + && !(*WriteProc)(WriteProcArg, format_ptr, num_chars)) { + return -1; + } + + break; + } + + num_chars = curr_format - format_ptr; + chars_written += num_chars; + + if (num_chars && !(*WriteProc)(WriteProcArg, format_ptr, num_chars)) { + return -1; + } + + format_ptr = curr_format; + format_ptr = parse_format(format_ptr, (va_list*)arg, &format); + + switch (format.conversion_char) { + case 'd': + case 'i': + if (format.argument_options == long_argument) { + long_num = va_arg(arg, signed long); + } else if (format.argument_options == long_long_argument) { + long_long_num = va_arg(arg, signed long long); + } else { + long_num = va_arg(arg, int); + } + + if (format.argument_options == short_argument) { + long_num = (signed short)long_num; + } + + if (format.argument_options == char_argument) { + long_num = (signed char)long_num; + } + + if (format.argument_options == long_long_argument) { + if (!(buff_ptr + = longlong2str(long_long_num, buff + 512, &format))) { + goto conversion_error; + } + } else { + if (!(buff_ptr = long2str(long_num, buff + 512, &format))) { + goto conversion_error; + } + } + + num_chars = buff + 512 - 1 - buff_ptr; + break; + + case 'o': + case 'u': + case 'x': + case 'X': + if (format.argument_options == long_argument) { + long_num = va_arg(arg, unsigned long); + } else if (format.argument_options == long_long_argument) { + long_long_num = va_arg(arg, signed long long); + } else { + long_num = va_arg(arg, unsigned int); + } + + if (format.argument_options == short_argument) { + long_num = (unsigned short)long_num; + } + + if (format.argument_options == char_argument) { + long_num = (unsigned char)long_num; + } + + if (format.argument_options == long_long_argument) { + if (!(buff_ptr + = longlong2str(long_long_num, buff + 512, &format))) { + goto conversion_error; + } + } else { + if (!(buff_ptr = long2str(long_num, buff + 512, &format))) { + goto conversion_error; + } + } + + num_chars = buff + 512 - 1 - buff_ptr; + break; + + case 'f': + case 'e': + case 'E': + case 'g': + case 'G': + if (!(buff_ptr = float2str(arg, buff + 512, &format, 0))) { + goto conversion_error; + } + + num_chars = buff + 512 - 1 - buff_ptr; + break; + + case 's': + if (format.argument_options == wchar_argument) { + wchar_t* wcs_ptr = va_arg(arg, wchar_t*); + + if (wcs_ptr == NULL) { + wcs_ptr = L""; + } + + if ((num_chars = wcstombs(buff, wcs_ptr, sizeof(buff))) < 0) { + goto conversion_error; + } + + buff_ptr = &buff[0]; + } else { + buff_ptr = va_arg(arg, char*); + } + + if (buff_ptr == NULL) { + buff_ptr = ""; + } + + if (format.alternate_form) { + num_chars = (unsigned char)*buff_ptr++; + + if (format.precision_specified + && num_chars > format.precision) { + num_chars = format.precision; + } + } else if (format.precision_specified) { + num_chars = format.precision; + + if ((string_end + = (char*)memchr((unsigned char*)buff_ptr, 0, num_chars)) + != 0) { + num_chars = string_end - buff_ptr; + } + } else { + num_chars = strlen(buff_ptr); + } + + break; + + case 'n': + buff_ptr = va_arg(arg, char*); + + switch (format.argument_options) { + case normal_argument: + *(int*)buff_ptr = chars_written; + break; + case short_argument: + *(signed short*)buff_ptr = chars_written; + break; + case long_argument: + *(signed long*)buff_ptr = chars_written; + break; + case long_long_argument: + *(signed long long*)buff_ptr = chars_written; + break; + } + + continue; + + case 'c': + buff_ptr = buff; + *buff_ptr = va_arg(arg, int); + num_chars = 1; + break; + + case '%': + buff_ptr = buff; + *buff_ptr = '%'; + num_chars = 1; + break; + + case 0xFF: + default: + conversion_error: + num_chars = strlen(curr_format); + chars_written += num_chars; + + if (num_chars + && !(*WriteProc)(WriteProcArg, curr_format, num_chars)) { + return -1; + } + + return chars_written; + break; + } + + field_width = num_chars; + + if (format.justification_options != left_justification) { + fill_char = (format.justification_options == zero_fill) ? '0' : ' '; + + if (((*buff_ptr == '+') || (*buff_ptr == '-')) + && (fill_char == '0')) { + if ((*WriteProc)(WriteProcArg, buff_ptr, 1) == 0) { + return -1; + } + + ++buff_ptr; + num_chars--; + } + + while (field_width < format.field_width) { + if ((*WriteProc)(WriteProcArg, &fill_char, 1) == 0) { + return -1; + } + + ++field_width; + } + } + + if (num_chars && !(*WriteProc)(WriteProcArg, buff_ptr, num_chars)) { + return -1; + } + + if (format.justification_options == left_justification) { + while (field_width < format.field_width) { + char blank = ' '; + + if ((*WriteProc)(WriteProcArg, &blank, 1) == 0) { + return -1; + } + + ++field_width; + } + } + + chars_written += field_width; + } + + return chars_written; +} + +static void* __FileWrite(void* pFile, const char* pBuffer, size_t char_num) +{ + return (fwrite(pBuffer, 1, char_num, (FILE*)pFile) == char_num ? pFile : 0); +} + +static void* __StringWrite(void* pCtrl, const char* pBuffer, size_t char_num) +{ + size_t chars; + __OutStrCtrl* ctrl = (__OutStrCtrl*)pCtrl; + void* res; + + chars = ((ctrl->CharsWritten + char_num) <= ctrl->MaxCharCount) + ? char_num + : ctrl->MaxCharCount - ctrl->CharsWritten; + res = memcpy(ctrl->CharStr + ctrl->CharsWritten, pBuffer, chars); + ctrl->CharsWritten += chars; + return res; +} + +int printf(const char* format, ...) +{ + int res; + + if (fwide(stdout, -1) >= 0) { + return -1; + } + + { + va_list args; + va_start(args, format); + res = __pformatter(&__FileWrite, (void*)stdout, format, args); + } + + return res; +} + +int vprintf(const char* format, va_list arg) +{ + int ret; + + if (fwide(stdout, -1) >= 0) { + return -1; + } + + ret = __pformatter(&__FileWrite, (void*)stdout, format, arg); + return ret; +} + +int vsnprintf(char* s, size_t n, const char* format, va_list arg) +{ + int end; + __OutStrCtrl osc; + osc.CharStr = s; + osc.MaxCharCount = n; + osc.CharsWritten = 0; + + end = __pformatter(&__StringWrite, &osc, format, arg); + + s[(end < n) ? end : n - 1] = '\0'; + + return end; +} + +int snprintf(char* s, size_t n, const char* format, ...) +{ + va_list args; + va_start(args, format); + return vsnprintf(s, n, format, args); +} + +int sprintf(char* s, const char* format, ...) +{ + va_list args; + va_start(args, format); + return vsnprintf(s, 0xFFFFFFFF, format, args); +} diff --git a/src/MSL_C.PPCEABI.bare.H/rand.c b/src/MSL_C.PPCEABI.bare.H/rand.c new file mode 100644 index 00000000..4d57c3e5 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/rand.c @@ -0,0 +1,13 @@ +#include "dolphin.h" + +// rand.c from Runtime library + +u32 next = 1; + +u32 rand(void) +{ + next = 0x41C64E6D * next + 12345; + return (next >> 16) & 0x7FFF; +} + +void srand(u32 seed) { next = seed; } diff --git a/src/MSL_C.PPCEABI.bare.H/s_atan.c b/src/MSL_C.PPCEABI.bare.H/s_atan.c new file mode 100644 index 00000000..6d72b440 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/s_atan.c @@ -0,0 +1,148 @@ + +/* @(#)s_atan.c 1.3 95/01/18 */ +/** + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +/* atan(x) + * Method + * 1. Reduce x to positive by atan(x) = -atan(-x). + * 2. According to the integer k=4t+0.25 chopped, t=x, the argument + * is further reduced to one of the following intervals and the + * arctangent of t is evaluated by the corresponding formula: + * + * [0,7/16] atan(x) = t-t^3*(a1+t^2*(a2+...(a10+t^2*a11)...) + * [7/16,11/16] atan(x) = atan(1/2) + atan( (t-0.5)/(1+t/2) ) + * [11/16.19/16] atan(x) = atan( 1 ) + atan( (t-1)/(1+t) ) + * [19/16,39/16] atan(x) = atan(3/2) + atan( (t-1.5)/(1+1.5t) ) + * [39/16,INF] atan(x) = atan(INF) + atan( -1/t ) + * + * Constants: + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + */ + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common_Embedded/Math/fdlibm.h" + +#ifdef __STDC__ +static const double atanhi[] = { +#else +static double atanhi[] = { +#endif + 4.63647609000806093515e-01, /* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */ + 7.85398163397448278999e-01, /* atan(1.0)hi 0x3FE921FB, 0x54442D18 */ + 9.82793723247329054082e-01, /* atan(1.5)hi 0x3FEF730B, 0xD281F69B */ + 1.57079632679489655800e+00, /* atan(inf)hi 0x3FF921FB, 0x54442D18 */ +}; + +#ifdef __STDC__ +static const double atanlo[] = { +#else +static double atanlo[] = { +#endif + 2.26987774529616870924e-17, /* atan(0.5)lo 0x3C7A2B7F, 0x222F65E2 */ + 3.06161699786838301793e-17, /* atan(1.0)lo 0x3C81A626, 0x33145C07 */ + 1.39033110312309984516e-17, /* atan(1.5)lo 0x3C700788, 0x7AF0CBBD */ + 6.12323399573676603587e-17, /* atan(inf)lo 0x3C91A626, 0x33145C07 */ +}; + +#ifdef __STDC__ +static const double aT[] = { +#else +static double aT[] = { +#endif + 3.33333333333329318027e-01, /* 0x3FD55555, 0x5555550D */ + -1.99999999998764832476e-01, /* 0xBFC99999, 0x9998EBC4 */ + 1.42857142725034663711e-01, /* 0x3FC24924, 0x920083FF */ + -1.11111104054623557880e-01, /* 0xBFBC71C6, 0xFE231671 */ + 9.09088713343650656196e-02, /* 0x3FB745CD, 0xC54C206E */ + -7.69187620504482999495e-02, /* 0xBFB3B0F2, 0xAF749A6D */ + 6.66107313738753120669e-02, /* 0x3FB10D66, 0xA0D03D51 */ + -5.83357013379057348645e-02, /* 0xBFADDE2D, 0x52DEFD9A */ + 4.97687799461593236017e-02, /* 0x3FA97B4B, 0x24760DEB */ + -3.65315727442169155270e-02, /* 0xBFA2B444, 0x2C6A6C2F */ + 1.62858201153657823623e-02, /* 0x3F90AD3A, 0xE322DA11 */ +}; + +#ifdef __STDC__ +static const double +#else +static double +#endif + one + = 1.0, + huge = 1.0e300; + +#ifdef __STDC__ +double atan(double x) +#else +double atan(x) +double x; +#endif +{ + double w, s1, s2, z; + int ix, hx, id; + + hx = __HI(x); + ix = hx & 0x7fffffff; + if (ix >= 0x44100000) { /* if |x| >= 2^66 */ + if (ix > 0x7ff00000 || (ix == 0x7ff00000 && (__LO(x) != 0))) + return x + x; /* NaN */ + if (hx > 0) + return atanhi[3] + atanlo[3]; + else + return -atanhi[3] - atanlo[3]; + } + if (ix < 0x3fdc0000) { /* |x| < 0.4375 */ + if (ix < 0x3e200000) { /* |x| < 2^-29 */ + if (huge + x > one) + return x; /* raise inexact */ + } + id = -1; + } else { + x = fabs__Fd(x); + if (ix < 0x3ff30000) { /* |x| < 1.1875 */ + if (ix < 0x3fe60000) { /* 7/16 <=|x|<11/16 */ + id = 0; + x = (2.0 * x - one) / (2.0 + x); + } else { /* 11/16<=|x|< 19/16 */ + id = 1; + x = (x - one) / (x + one); + } + } else { + if (ix < 0x40038000) { /* |x| < 2.4375 */ + id = 2; + x = (x - 1.5) / (one + 1.5 * x); + } else { /* 2.4375 <= |x| < 2^66 */ + id = 3; + x = -1.0 / x; + } + } + } + /* end of argument reduction */ + z = x * x; + w = z * z; + /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */ + s1 = z + * (aT[0] + + w + * (aT[2] + + w * (aT[4] + w * (aT[6] + w * (aT[8] + w * aT[10]))))); + s2 = w * (aT[1] + w * (aT[3] + w * (aT[5] + w * (aT[7] + w * aT[9])))); + if (id < 0) + return x - x * (s1 + s2); + else { + z = atanhi[id] - ((x * (s1 + s2) - atanlo[id]) - x); + return (hx < 0) ? -z : z; + } +} diff --git a/src/MSL_C.PPCEABI.bare.H/s_frexp.c b/src/MSL_C.PPCEABI.bare.H/s_frexp.c new file mode 100644 index 00000000..a7bb05c4 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/s_frexp.c @@ -0,0 +1,58 @@ +/* @(#)s_frexp.c 1.4 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * for non-zero x + * x = frexp(arg,&exp); + * return a double fp quantity x such that 0.5 <= |x| <1.0 + * and the corresponding binary exponent "exp". That is + * arg = x*2^exp. + * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg + * with *exp=0. + */ + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common_Embedded/Math/fdlibm.h" + +#ifdef __STDC__ +static const double +#else +static double +#endif + two54 + = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */ + +#ifdef __STDC__ +double frexp(double x, int* eptr) +#else +double frexp(x, eptr) +double x; +int* eptr; +#endif +{ + int hx, ix, lx; + hx = __HI(x); + ix = 0x7fffffff & hx; + lx = __LO(x); + *eptr = 0; + if (ix >= 0x7ff00000 || ((ix | lx) == 0)) + return x; /* 0,inf,nan */ + if (ix < 0x00100000) { /* subnormal */ + x *= two54; + hx = __HI(x); + ix = hx & 0x7fffffff; + *eptr = -54; + } + *eptr += (ix >> 20) - 1022; + hx = (hx & 0x800fffff) | 0x3fe00000; + __HI(x) = hx; + return x; +} diff --git a/src/MSL_C.PPCEABI.bare.H/scanf.c b/src/MSL_C.PPCEABI.bare.H/scanf.c new file mode 100644 index 00000000..a8f273ec --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/scanf.c @@ -0,0 +1,34 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/scanf.h" + +int __StringRead(void* pPtr, int ch, int act) +{ + char ret; + __InStrCtrl* Iscp = (__InStrCtrl*)pPtr; + + switch (act) { + case __GetAChar: + ret = *(Iscp->NextChar); + + if (ret == '\0') { + Iscp->NullCharDetected = 1; + return -1; + } else { + Iscp->NextChar++; + return ret; + } + + case __UngetAChar: + if (Iscp->NullCharDetected == 0) { + Iscp->NextChar--; + } else { + Iscp->NullCharDetected = 0; + } + + return ch; + + case __TestForError: + return Iscp->NullCharDetected; + } + + return 0; +} diff --git a/src/MSL_C.PPCEABI.bare.H/string.c b/src/MSL_C.PPCEABI.bare.H/string.c new file mode 100644 index 00000000..833447df --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/string.c @@ -0,0 +1,257 @@ +#include "string.h" + +static int K1 = 0x80808080; +static int K2 = 0xFEFEFEFF; + +size_t strlen(const char* str) +{ + size_t len = -1; + unsigned char* p = (unsigned char*)str - 1; + + do { + len++; + } while (*++p); + + return len; +} + +char* strcpy(char* dst, const char* src) +{ + register unsigned char *destb, *fromb; + register unsigned long w, t, align; + register unsigned int k1; + register unsigned int k2; + + fromb = (unsigned char*)src; + destb = (unsigned char*)dst; + + if ((align = ((int)fromb & 3)) != ((int)destb & 3)) { + goto bytecopy; + } + + if (align) { + if ((*destb = *fromb) == 0) { + return dst; + } + + for (align = 3 - align; align; align--) { + if ((*(++destb) = *(++fromb)) == 0) { + return dst; + } + } + ++destb; + ++fromb; + } + + k1 = K1; + k2 = K2; + + w = *((int*)(fromb)); + + t = w + k2; + + t &= k1; + if (t) { + goto bytecopy; + } + --((int*)(destb)); + + do { + *(++((int*)(destb))) = w; + w = *(++((int*)(fromb))); + + t = w + k2; + t &= k1; + if (t) { + goto adjust; + } + } while (1); + +adjust: + ++((int*)(destb)); + +bytecopy: + if ((*destb = *fromb) == 0) { + return dst; + } + + do { + if ((*(++destb) = *(++fromb)) == 0) { + return dst; + } + } while (1); + + return dst; +} + +char* strncpy(char* dst, const char* src, size_t n) +{ + const unsigned char* p = (const unsigned char*)src - 1; + unsigned char* q = (unsigned char*)dst - 1; + + n++; + while (--n) { + if (!(*++q = *++p)) { + while (--n) { + *++q = 0; + } + break; + } + } + + return dst; +} + +char* strcat(char* dst, const char* src) +{ + const unsigned char* p = (unsigned char*)src - 1; + unsigned char* q = (unsigned char*)dst - 1; + + while (*++q) { } + + q--; + + while (*++q = *++p) { } + + return dst; +} + +int strcmp(const char* str1, const char* str2) +{ + register unsigned char* left = (unsigned char*)str1; + register unsigned char* right = (unsigned char*)str2; + unsigned long align, l1, r1, x; + + l1 = *left; + r1 = *right; + if (l1 - r1) { + return l1 - r1; + } + + if ((align = ((int)left & 3)) != ((int)right & 3)) { + goto bytecopy; + } + + if (align) { + if (l1 == 0) { + return 0; + } + for (align = 3 - align; align; align--) { + l1 = *(++left); + r1 = *(++right); + if (l1 - r1) { + return l1 - r1; + } + if (l1 == 0) { + return 0; + } + } + left++; + right++; + } + + l1 = *(int*)left; + r1 = *(int*)right; + x = l1 + K2; + if (x & K1) { + goto adjust; + } + + while (l1 == r1) { + l1 = *(++((int*)(left))); + r1 = *(++((int*)(right))); + x = l1 + K2; + if (x & K1) { + goto adjust; + } + } + + if (l1 > r1) { + return 1; + } + return -1; + +adjust: + l1 = *left; + r1 = *right; + if (l1 - r1) { + return l1 - r1; + } + +bytecopy: + if (l1 == 0) { + return 0; + } + + do { + l1 = *(++left); + r1 = *(++right); + if (l1 - r1) { + return l1 - r1; + } + if (l1 == 0) { + return 0; + } + } while (1); +} + +char* strchr(const char* str, int c) +{ + const unsigned char* p = (unsigned char*)str - 1; + unsigned long chr = (c & 0xFF); + + unsigned long ch; + while (ch = *++p) { + if (ch == chr) { + return (char*)p; + } + } + + return chr ? NULL : (char*)p; +} + +char* strrchr(const char* str, int c) +{ + const unsigned char* p = (unsigned char*)str - 1; + const unsigned char* q = NULL; + unsigned long chr = (c & 0xFF); + + unsigned long ch; + while (ch = *++p) { + if (ch == chr) { + q = p; + } + } + + if (q != NULL) { + return (char*)q; + } + + return chr ? NULL : (char*)p; +} + +char* strstr(const char* str, const char* pat) +{ + const unsigned char* s1 = (const unsigned char*)str - 1; + const unsigned char* p1 = (const unsigned char*)pat - 1; + unsigned long firstc, c1, c2; + + if ((pat == 0) || (!(firstc = *++p1))) { + return (char*)str; + } + + while (c1 = *++s1) { + if (c1 == firstc) { + const unsigned char* s2 = s1 - 1; + const unsigned char* p2 = p1 - 1; + + while ((c1 = *++s2) == (c2 = *++p2) && c1) + ; + + if (!c2) + return (char*)s1; + } + } + + return NULL; +} diff --git a/src/MSL_C.PPCEABI.bare.H/strtoul.c b/src/MSL_C.PPCEABI.bare.H/strtoul.c new file mode 100644 index 00000000..e40b9fac --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/strtoul.c @@ -0,0 +1,199 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/strtoul.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ctype.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/errno.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/limits.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/scanf.h" + +enum scan_states { + start = 0x01, + check_for_zero = 0x02, + leading_zero = 0x04, + need_digit = 0x08, + digit_loop = 0x10, + finished = 0x20, + failure = 0x40 +}; + +#define final_state(scan_state) (scan_state & (finished | failure)) +#define success(scan_state) \ + (scan_state & (leading_zero | digit_loop | finished)) +#define fetch() (count++, (*ReadProc)(ReadProcArg, 0, __GetAChar)) +#define unfetch(c) (*ReadProc)(ReadProcArg, c, __UngetAChar) + +unsigned long __strtoul(int base, int max_width, + int (*ReadProc)(void*, int, int), void* ReadProcArg, + int* chars_scanned, int* negative, int* overflow) +{ + int scan_state = start; + int count = 0; + unsigned long value = 0; + unsigned long value_max = 0; + int c; + + *negative = *overflow = 0; + + if (base < 0 || base == 1 || base > 36 || max_width < 1) { + scan_state = failure; + } else { + c = fetch(); + } + + if (base != 0) + value_max = ULONG_MAX / base; + + while (count <= max_width && c != -1 && !final_state(scan_state)) { + switch (scan_state) { + case start: + if (isspace(c)) { + c = fetch(); + break; + } + + if (c == '+') { + c = fetch(); + } else if (c == '-') { + c = fetch(); + *negative = 1; + } + + scan_state = check_for_zero; + break; + + case check_for_zero: + if (base == 0 || base == 16) { + if (c == '0') { + scan_state = leading_zero; + c = fetch(); + break; + } + } + + scan_state = need_digit; + break; + + case 4: + if (c == 'X' || c == 'x') { + base = 16; + scan_state = need_digit; + c = fetch(); + break; + } + + if (base == 0) + base = 8; + + scan_state = digit_loop; + break; + + case need_digit: + case digit_loop: + if (base == 0) + base = 10; + + if (!value_max) { + value_max = ULONG_MAX / base; + } + + if (isdigit(c)) { + if ((c -= '0') >= base) { + if (scan_state == digit_loop) + scan_state = finished; + else + scan_state = failure; + + c += '0'; + break; + } + } else if (!isalpha(c) || (toupper(c) - 'A' + 10) >= base) { + if (scan_state == digit_loop) + scan_state = finished; + else + scan_state = failure; + + break; + } else { + c = toupper(c) - 'A' + 10; + } + + if (value > value_max) + *overflow = 1; + + value *= base; + + if (c > (ULONG_MAX - value)) + *overflow = 1; + + value += c; + scan_state = digit_loop; + c = fetch(); + break; + } + } + + if (!success(scan_state)) { + value = 0; + count = 0; + } else { + count--; + } + + *chars_scanned = count; + + unfetch(c); + + return value; +} + +unsigned long strtoul(const char* str, char** end, int base) +{ + unsigned long value; + int count, negative, overflow; + + __InStrCtrl isc; + isc.NextChar = (char*)str; + isc.NullCharDetected = 0; + + value = __strtoul(base, 0x7FFFFFFF, &__StringRead, (void*)&isc, &count, + &negative, &overflow); + + if (end) { + *end = (char*)str + count; + } + + if (overflow) { + value = ULONG_MAX; + errno = 0x22; + } else if (negative) { + value = -value; + } + + return value; +} + +long strtol(const char* str, char** end, int base) +{ + unsigned long uvalue; + long svalue; + int count, negative, overflow; + + __InStrCtrl isc; + isc.NextChar = (char*)str; + isc.NullCharDetected = 0; + + uvalue = __strtoul(base, 0x7FFFFFFF, &__StringRead, (void*)&isc, &count, + &negative, &overflow); + + if (end) { + *end = (char*)str + count; + } + + if (overflow || (!negative && uvalue > LONG_MAX) + || (negative && uvalue > -LONG_MIN)) { + svalue = (negative ? -LONG_MIN : LONG_MAX); + errno = ERANGE; + } else { + svalue = (negative ? (long)-uvalue : (long)uvalue); + } + + return svalue; +} diff --git a/src/MSL_C.PPCEABI.bare.H/w_atan2.c b/src/MSL_C.PPCEABI.bare.H/w_atan2.c new file mode 100644 index 00000000..42f1b297 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/w_atan2.c @@ -0,0 +1,39 @@ +/* @(#)w_atan2.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +/* + * wrapper atan2(y,x) + */ + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common_Embedded/Math/fdlibm.h" + +#ifdef __STDC__ +double atan2(double y, double x) /* wrapper atan2 */ +#else +double atan2(y, x) /* wrapper atan2 */ +double y, x; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_atan2(y, x); +#else + double z; + z = __ieee754_atan2(y, x); + if (_LIB_VERSION == _IEEE_ || isnan(x) || isnan(y)) + return z; + if (x == 0.0 && y == 0.0) { + return __kernel_standard(y, x, 3); /* atan2(+-0,+-0) */ + } else + return z; +#endif +} diff --git a/src/MSL_C.PPCEABI.bare.H/wchar_io.c b/src/MSL_C.PPCEABI.bare.H/wchar_io.c new file mode 100644 index 00000000..4d5d32b5 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/wchar_io.c @@ -0,0 +1,22 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/wchar_io.h" + +int fwide(FILE* file, int mode) +{ + if (file->file_mode.file_kind == __closed_file) { + return 0; + } + + switch (file->file_mode.file_orientation) { + case UNORIENTED: + if (mode > 0) { + file->file_mode.file_orientation = WIDE_ORIENTED; + } else if (mode < 0) { + file->file_mode.file_orientation = CHAR_ORIENTED; + } + return mode; + case WIDE_ORIENTED: + return 1; + case CHAR_ORIENTED: + return -1; + } +} diff --git a/src/TRK_MINNOW_DOLPHIN/__exception.s b/src/TRK_MINNOW_DOLPHIN/__exception.s new file mode 100644 index 00000000..a5c63065 --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/__exception.s @@ -0,0 +1,2018 @@ +.include "macros.inc" +.file "__exception.s" + +# 0x80003534..0x80005468 | size: 0x1F34 +.section .init, "ax" +.balign 4 +# .init:0x0 | 0x80003534 | size: 0x0 +.sym gTRKInterruptVectorTable, global + +# .init:0x0 | 0x80003534 | size: 0x1F34 +.fn pad_00_80003534_init, local +.4byte 0x4D657472 +xoris r23, r27, 0x6572 +xori r19, r27, 0x2054 +ori r18, r11, 0x6765 +andis. r0, r1, 0x5265 +andi. r9, r27, 0x6465 +xoris r20, r19, 0x204b +oris r18, r11, 0x6e65 +xoris r0, r1, 0x666f +andi. r0, r17, 0x506f +andis. r5, r27, 0x7250 +.L_80003560: + .4byte 0x43000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + b 0x1e34 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mfsrr0 r2 + icbi r0, r2 + mfdar r2 + dcbi r0, r2 + mfsprg r2, 1 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0x200 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0x300 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 +# .init:0x348 | 0x8000387C | size: 0x0 +.sym lbl_8000387C, global + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 +# .init:0x3AC | 0x800038E0 | size: 0x0 +.sym lbl_800038E0, global + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0x400 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0x500 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0x600 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0x700 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0x800 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0x900 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0xc00 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0xd00 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0xe00 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + b .L_80004488 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0xf20 + rfi +.L_80004488: + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0xf00 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mfcr r2 + mtsprg 2, r2 + mfmsr r2 + andis. r2, r2, 0x2 + beq .L_80004564 + mfmsr r2 + xoris r2, r2, 0x2 + sync + mtmsr r2 + sync + mtsprg 1, r2 +.L_80004564: + mfsprg r2, 2 + mtcrf 255, r2 + mfsprg r2, 1 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0x1000 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mfcr r2 + mtsprg 2, r2 + mfmsr r2 + andis. r2, r2, 0x2 + beq .L_80004664 + mfmsr r2 + xoris r2, r2, 0x2 + sync + mtmsr r2 + sync + mtsprg 1, r2 +.L_80004664: + mfsprg r2, 2 + mtcrf 255, r2 + mfsprg r2, 1 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0x1100 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mfcr r2 + mtsprg 2, r2 + mfmsr r2 + andis. r2, r2, 0x2 + beq .L_80004764 + mfmsr r2 + xoris r2, r2, 0x2 + sync + mtmsr r2 + sync + mtsprg 1, r2 +.L_80004764: + mfsprg r2, 2 + mtcrf 255, r2 + mfsprg r2, 1 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0x1200 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0x1300 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0x1400 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0x1600 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0x1700 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0x1c00 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0x1d00 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0x1e00 + rfi + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + .4byte 0x00000000 + mtsprg 1, r2 + mtsprg 2, r3 + mtsprg 3, r4 + mfsrr0 r2 + mfsrr1 r4 + mfmsr r3 + ori r3, r3, 0x30 + mtsrr1 r3 + lis r3, 0x800f + ori r3, r3, 0x4a0 + mtsrr0 r3 + li r3, 0x1f00 + rfi +.endfn pad_00_80003534_init diff --git a/src/TRK_MINNOW_DOLPHIN/dispatch.c b/src/TRK_MINNOW_DOLPHIN/dispatch.c new file mode 100644 index 00000000..76014bb6 --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/dispatch.c @@ -0,0 +1,43 @@ +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/dispatch.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msgbuf.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msghndlr.h" + +u32 gTRKDispatchTableSize; + +struct DispatchEntry { + int (*fn)(TRKBuffer*); +}; + +struct DispatchEntry gTRKDispatchTable[33] = { + { &TRKDoUnsupported }, { &TRKDoConnect }, { &TRKDoDisconnect }, + { &TRKDoReset }, { &TRKDoVersions }, { &TRKDoSupportMask }, + { &TRKDoCPUType }, { &TRKDoUnsupported }, { &TRKDoUnsupported }, + { &TRKDoUnsupported }, { &TRKDoUnsupported }, { &TRKDoUnsupported }, + { &TRKDoUnsupported }, { &TRKDoUnsupported }, { &TRKDoUnsupported }, + { &TRKDoUnsupported }, { &TRKDoReadMemory }, { &TRKDoWriteMemory }, + { &TRKDoReadRegisters }, { &TRKDoWriteRegisters }, { &TRKDoUnsupported }, + { &TRKDoUnsupported }, { &TRKDoFlushCache }, { &TRKDoUnsupported }, + { &TRKDoContinue }, { &TRKDoStep }, { &TRKDoStop }, + { &TRKDoUnsupported }, { &TRKDoUnsupported }, { &TRKDoUnsupported }, + { &TRKDoUnsupported }, { &TRKDoUnsupported }, +}; + +DSError TRKInitializeDispatcher() +{ + gTRKDispatchTableSize = 32; + return DS_NoError; +} + +DSError TRKDispatchMessage(TRKBuffer* buffer) +{ + DSError error; + u8 command; + + error = DS_DispatchError; + TRKSetBufferPosition(buffer, 0); + TRKReadBuffer1_ui8(buffer, &command); + if (command < gTRKDispatchTableSize) { + error = gTRKDispatchTable[command].fn(buffer); + } + return error; +} diff --git a/src/TRK_MINNOW_DOLPHIN/dolphin_trk.c b/src/TRK_MINNOW_DOLPHIN/dolphin_trk.c new file mode 100644 index 00000000..31153cd6 --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/dolphin_trk.c @@ -0,0 +1,137 @@ +#include "TRK_MINNOW_DOLPHIN/Os/dolphin/dolphin_trk.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/main_TRK.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/mem_TRK.h" +#include "TRK_MINNOW_DOLPHIN/Os/dolphin/dolphin_trk_glue.h" +#include "TRK_MINNOW_DOLPHIN/ppc/Generic/targimpl.h" +#include "TRK_MINNOW_DOLPHIN/ppc/Generic/flush_cache.h" +#include "dolphin/ar.h" +#include "stddef.h" + +#define EXCEPTIONMASK_ADDR 0x80000044 + +static u32 lc_base; + +static u32 TRK_ISR_OFFSETS[15] = { PPC_SystemReset, + PPC_MachineCheck, + PPC_DataStorage, + PPC_InstructionStorage, + PPC_ExternalInterrupt, + PPC_Alignment, + PPC_Program, + PPC_FloatingPointUnavaiable, + PPC_Decrementer, + PPC_SystemCall, + PPC_Trace, + PPC_PerformanceMonitor, + PPC_InstructionAddressBreakpoint, + PPC_SystemManagementInterrupt, + PPC_ThermalManagementInterrupt }; + +__declspec(section ".init") void __TRK_reset(void) { __TRK_copy_vectors(); } + +asm void InitMetroTRK() +{ +#ifdef __MWERKS__ // clang-format off + nofralloc + + addi r1, r1, -4 + stw r3, 0(r1) + lis r3, gTRKCPUState@h + ori r3, r3, gTRKCPUState@l + stmw r0, ProcessorState_PPC.Default.GPR(r3) //Save the gprs + lwz r4, 0(r1) + addi r1, r1, 4 + stw r1, ProcessorState_PPC.Default.GPR[1](r3) + stw r4, ProcessorState_PPC.Default.GPR[3](r3) + mflr r4 + stw r4, ProcessorState_PPC.Default.LR(r3) + stw r4, ProcessorState_PPC.Default.PC(r3) + mfcr r4 + stw r4, ProcessorState_PPC.Default.CR(r3) + //??? + mfmsr r4 + ori r3, r4, (1 << (31 - 16)) + xori r3, r3, (1 << (31 - 16)) + mtmsr r3 + mtsrr1 r4 //Copy msr to srr1 + //Save misc registers to gTRKCPUState + bl TRKSaveExtended1Block + lis r3, gTRKCPUState@h + ori r3, r3, gTRKCPUState@l + lmw r0, ProcessorState_PPC.Default.GPR(r3) //Restore the gprs + //Reset IABR and DABR + li r0, 0 + mtspr 0x3f2, r0 + mtspr 0x3f5, r0 + //Restore stack pointer + lis r1, 0x80426008@h + ori r1, r1, 0x80426008@l + mr r3, r5 + bl InitMetroTRKCommTable //Initialize comm table + /* + If InitMetroTRKCommTable returned 1 (failure), an invalid hardware + id or the id for GDEV was somehow passed. Since only BBA or NDEV + are supported, we return early. Otherwise, we proceed with + starting up TRK. + */ + cmpwi r3, 1 + bne initCommTableSuccess + /* + BUG: The code probably orginally reloaded gTRKCPUState here, but + as is it will read the returned value of InitMetroTRKCommTable + as a TRKCPUState struct pointer, causing the CPU to return to + a garbage code address. + */ + lwz r4, ProcessorState_PPC.Default.LR(r3) + mtlr r4 + lmw r0, ProcessorState_PPC.Default.GPR(r3) //Restore the gprs + blr +initCommTableSuccess: + b TRK_main //Jump to TRK_main +#endif // clang-format on +} + +void EnableMetroTRKInterrupts(void) { EnableEXI2Interrupts(); } + +u32 TRKTargetTranslate(u32 param_0) +{ + if (param_0 >= lc_base) { + if ((param_0 < lc_base + 0x4000) + && ((gTRKCPUState.Extended1.DBAT3U & 3) != 0)) { + return param_0; + } + } + + return param_0 & 0x3FFFFFFF | 0x80000000; +} + +extern u8 gTRKInterruptVectorTable[]; + +void TRK_copy_vector(u32 offset) +{ + void* destPtr = (void*)TRKTargetTranslate(offset); + TRK_memcpy(destPtr, gTRKInterruptVectorTable + offset, 0x100); + TRK_flush_cache(destPtr, 0x100); +} + +void __TRK_copy_vectors(void) +{ + int i; + u32 mask; + + mask = *(u32*)TRKTargetTranslate(0x44); + + for (i = 0; i <= 14; ++i) { + if (mask & (1 << i)) { + TRK_copy_vector(TRK_ISR_OFFSETS[i]); + } + } +} + +DSError TRKInitializeTarget() +{ + gTRKState.isStopped = TRUE; + gTRKState.msr = __TRK_get_MSR(); + lc_base = 0xE0000000; + return DS_NoError; +} diff --git a/src/TRK_MINNOW_DOLPHIN/dolphin_trk_glue.c b/src/TRK_MINNOW_DOLPHIN/dolphin_trk_glue.c new file mode 100644 index 00000000..9a55362b --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/dolphin_trk_glue.c @@ -0,0 +1,116 @@ +#include "TRK_MINNOW_DOLPHIN/Os/dolphin/dolphin_trk_glue.h" +#include "TRK_MINNOW_DOLPHIN/ppc/Generic/targimpl.h" +#include "OdemuExi2/odemuexi/DebuggerDriver.h" +#include "amcstubs/AmcExi2Stubs.h" +#include "PowerPC_EABI_Support/MetroTRK/trk.h" + +DBCommTable gDBCommTable = {}; + +asm void TRKLoadContext(OSContext* ctx, u32) +{ +#ifdef __MWERKS__ // clang-format off + nofralloc + lwz r0, OSContext.gpr[0](r3) + lwz r1, OSContext.gpr[1](r3) + lwz r2, OSContext.gpr[2](r3) + lhz r5, OSContext.state(r3) + rlwinm. r6, r5, 0, 0x1e, 0x1e + beq lbl_80371C1C + rlwinm r5, r5, 0, 0x1f, 0x1d + sth r5, OSContext.state(r3) + lmw r5, OSContext.gpr[5](r3) + b lbl_80371C20 +lbl_80371C1C: + lmw r13, OSContext.gpr[13](r3) +lbl_80371C20: + mr r31, r3 + mr r3, r4 + lwz r4, OSContext.cr(r31) + mtcrf 0xff, r4 + lwz r4, OSContext.lr(r31) + mtlr r4 + lwz r4, OSContext.ctr(r31) + mtctr r4 + lwz r4, OSContext.xer(r31) + mtxer r4 + mfmsr r4 + rlwinm r4, r4, 0, 0x11, 0xf //Turn off external exceptions + rlwinm r4, r4, 0, 0x1f, 0x1d //Turn off recoverable exception flag + mtmsr r4 + mtsprg 1, r2 + lwz r4, OSContext.gpr[3](r31) + mtsprg 2, r4 + lwz r4, OSContext.gpr[4](r31) + mtsprg 3, r4 + lwz r2, OSContext.srr0(r31) + lwz r4, OSContext.srr1(r31) + lwz r31, OSContext.gpr[31](r31) + b TRKInterruptHandler +#endif // clang-format on +} + +void TRKEXICallBack(__OSInterrupt param_0, OSContext* ctx) +{ + OSEnableScheduler(); + TRKLoadContext(ctx, 0x500); +} + +int InitMetroTRKCommTable(int hwId) +{ + int result; + + if (hwId == HARDWARE_GDEV) { + result = Hu_IsStub(); + + gDBCommTable.initialize_func = DBInitComm; + gDBCommTable.init_interrupts_func = DBInitInterrupts; + gDBCommTable.peek_func = DBQueryData; + gDBCommTable.read_func = DBRead; + gDBCommTable.write_func = DBWrite; + gDBCommTable.open_func = DBOpen; + gDBCommTable.close_func = DBClose; + } else { + result = AMC_IsStub(); + + gDBCommTable.initialize_func = EXI2_Init; + gDBCommTable.init_interrupts_func = EXI2_EnableInterrupts; + gDBCommTable.peek_func = EXI2_Poll; + gDBCommTable.read_func = EXI2_ReadN; + gDBCommTable.write_func = EXI2_WriteN; + gDBCommTable.open_func = EXI2_Reserve; + gDBCommTable.close_func = EXI2_Unreserve; + } + + return result; +} + +void TRKUARTInterruptHandler() { } + +DSError TRKInitializeIntDrivenUART(u32 param_0, u32 param_1, u32 param_2, + volatile u8** param_3) +{ + gDBCommTable.initialize_func(param_3, TRKEXICallBack); + return DS_NoError; +} + +void EnableEXI2Interrupts(void) { gDBCommTable.init_interrupts_func(); } + +int TRKPollUART(void) { return gDBCommTable.peek_func(); } + +UARTError TRKReadUARTN(void* bytes, u32 length) +{ + int readErr = gDBCommTable.read_func(bytes, length); + return readErr == 0 ? 0 : -1; +} + +UARTError TRKWriteUARTN(const void* bytes, u32 length) +{ + int writeErr = gDBCommTable.write_func(bytes, length); + return writeErr == 0 ? 0 : -1; +} + +void ReserveEXI2Port(void) { gDBCommTable.open_func(); } + +void UnreserveEXI2Port(void) { gDBCommTable.close_func(); } + +void TRK_board_display(char* str) { OSReport(str); } diff --git a/src/TRK_MINNOW_DOLPHIN/flush_cache.c b/src/TRK_MINNOW_DOLPHIN/flush_cache.c new file mode 100644 index 00000000..116d8d72 --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/flush_cache.c @@ -0,0 +1,26 @@ +#include "TRK_MINNOW_DOLPHIN/ppc/Generic/flush_cache.h" + +asm void TRK_flush_cache(register void* param_1, register int param_2) +{ +#ifdef __MWERKS__ // clang-format off + nofralloc + + lis r5, 0xFFFF + ori r5, r5, 0xFFF1 + and r5, r5, param_1 + subf r3, r5, param_1 + add r4, param_2, r3 + +loop: + dcbst 0, r5 + dcbf 0, r5 + sync + icbi 0, r5 + addic r5, r5, 8 + addic. r4, r4, -8 + bge loop + + isync + blr +#endif // clang-format on +} diff --git a/src/TRK_MINNOW_DOLPHIN/main_TRK.c b/src/TRK_MINNOW_DOLPHIN/main_TRK.c new file mode 100644 index 00000000..0ce137a8 --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/main_TRK.c @@ -0,0 +1,17 @@ +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/main_TRK.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/nubinit.h" + +static DSError TRK_mainError; + +DSError TRK_main(void) +{ + TRK_mainError = TRKInitializeNub(); + + if (TRK_mainError == DS_NoError) { + TRKNubWelcome(); + TRKNubMainLoop(); + } + + TRK_mainError = TRKTerminateNub(); + return TRK_mainError; +} diff --git a/src/TRK_MINNOW_DOLPHIN/mainloop.c b/src/TRK_MINNOW_DOLPHIN/mainloop.c new file mode 100644 index 00000000..62783f82 --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/mainloop.c @@ -0,0 +1,70 @@ +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/serpoll.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msgbuf.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/dispatch.h" +#include "TRK_MINNOW_DOLPHIN/Os/dolphin/targcont.h" +#include "TRK_MINNOW_DOLPHIN/ppc/Generic/targimpl.h" + +void TRKHandleRequestEvent(TRKEvent* event) +{ + TRKBuffer* buffer = TRKGetBuffer(event->msgBufID); + TRKDispatchMessage(buffer); +} + +void TRKHandleSupportEvent(TRKEvent* event) { TRKTargetSupportRequest(); } + +void TRKIdle() +{ + if (TRKTargetStopped() == FALSE) { + TRKTargetContinue(); + } +} + +void TRKNubMainLoop(void) +{ + void* msg; + TRKEvent event; + BOOL isShutdownRequested; + BOOL isNewInput; + + isShutdownRequested = FALSE; + isNewInput = FALSE; + while (isShutdownRequested == FALSE) { + if (TRKGetNextEvent(&event) != FALSE) { + isNewInput = FALSE; + + switch (event.eventType) { + case NUBEVENT_Null: + break; + + case NUBEVENT_Request: + TRKHandleRequestEvent(&event); + break; + + case NUBEVENT_Shutdown: + isShutdownRequested = TRUE; + break; + + case NUBEVENT_Breakpoint: + case NUBEVENT_Exception: + TRKTargetInterrupt(&event); + break; + + case NUBEVENT_Support: + TRKHandleSupportEvent(&event); + break; + } + + TRKDestructEvent(&event); + continue; + } + + if ((isNewInput == FALSE) || (*(u8*)gTRKInputPendingPtr != '\0')) { + isNewInput = TRUE; + TRKGetInput(); + continue; + } + + TRKIdle(); + isNewInput = FALSE; + } +} diff --git a/src/TRK_MINNOW_DOLPHIN/mem_TRK.c b/src/TRK_MINNOW_DOLPHIN/mem_TRK.c new file mode 100644 index 00000000..b25259fe --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/mem_TRK.c @@ -0,0 +1,83 @@ +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/mem_TRK.h" +#include "dolphin/types.h" + +void TRK_fill_mem(void *dest, int value, unsigned long length) +{ +#define cDest ((unsigned char *)dest) +#define lDest ((unsigned long *)dest) + unsigned long val = (unsigned char)value; + unsigned long i; + lDest = (unsigned long *)dest; + cDest = (unsigned char *)dest; + + cDest--; + + if (length >= 32) { + i = ~(unsigned long)dest & 3; + + if (i) { + length -= i; + do { + *++cDest = val; + } while (--i); + } + + if (val) { + val |= val << 24 | val << 16 | val << 8; + } + + lDest = (unsigned long *)(cDest + 1) - 1; + + i = length >> 5; + if (i) { + do { + *++lDest = val; + *++lDest = val; + *++lDest = val; + *++lDest = val; + *++lDest = val; + *++lDest = val; + *++lDest = val; + *++lDest = val; + } while (--i); + } + + i = (length & 31) >> 2; + + if (i) { + do { + *++lDest = val; + } while (--i); + } + + cDest = (unsigned char *)(lDest + 1) - 1; + + length &= 3; + } + + if (length) { + do { + *++cDest = val; + } while (--length); + } + +#undef cDest +#undef lDest +} + +__declspec(section ".init") void *TRK_memcpy(void *dst, const void *src, size_t n) +{ + const char *p; + char *q; + + for (p = (const char *)src - 1, q = (char *)dst - 1, n++; --n;) + *++q = *++p; + + return dst; +} + +__declspec(section ".init") void *TRK_memset(void *dst, int val, size_t n) +{ + TRK_fill_mem(dst, val, n); + return dst; +} diff --git a/src/TRK_MINNOW_DOLPHIN/mpc_7xx_603e.c b/src/TRK_MINNOW_DOLPHIN/mpc_7xx_603e.c new file mode 100644 index 00000000..04d4d3a9 --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/mpc_7xx_603e.c @@ -0,0 +1,248 @@ +#include "TRK_MINNOW_DOLPHIN/ppc/Generic/mpc_7xx_603e.h" +#include "TRK_MINNOW_DOLPHIN/ppc/Generic/targimpl.h" + +extern u8 gTRKRestoreFlags[9 + 3 /* padding */]; + +asm void TRKSaveExtended1Block() +{ +#ifdef __MWERKS__ // clang-format off + nofralloc + lis r2, gTRKCPUState@h /* 0x8044F338@h */ + ori r2, r2, gTRKCPUState@l /* 0x8044F338@l */ + mfsr r16, 0 + mfsr r17, 1 + mfsr r18, 2 + mfsr r19, 3 + mfsr r20, 4 + mfsr r21, 5 + mfsr r22, 6 + mfsr r23, 7 + mfsr r24, 8 + mfsr r25, 9 + mfsr r26, 0xa + mfsr r27, 0xb + mfsr r28, 0xc + mfsr r29, 0xd + mfsr r30, 0xe + mfsr r31, 0xf + stmw r16, 0x1a8(r2) + mftb r10, 0x10c + mftbu r11 + mfspr r12, 0x3f0 + mfspr r13, 0x3f1 + mfspr r14, 0x1b + mfpvr r15 + mfibatu r16, 0 + mfibatl r17, 0 + mfibatu r18, 1 + mfibatl r19, 1 + mfibatu r20, 2 + mfibatl r21, 2 + mfibatu r22, 3 + mfibatl r23, 3 + mfdbatu r24, 0 + mfdbatl r25, 0 + mfdbatu r26, 1 + mfdbatl r27, 1 + mfdbatu r28, 2 + mfdbatl r29, 2 + mfdbatu r30, 3 + mfdbatl r31, 3 + stmw r10, 0x1e8(r2) + mfspr r22, 0x19 + mfdar r23 + mfdsisr r24 + mfspr r25, 0x110 + mfspr r26, 0x111 + mfspr r27, 0x112 + mfspr r28, 0x113 + li r29, 0 + mfspr r30, 0x3f2 + mfspr r31, 0x11a + stmw r22, 0x25c(r2) + mfspr r20, 0x390 + mfspr r21, 0x391 + mfspr r22, 0x392 + mfspr r23, 0x393 + mfspr r24, 0x394 + mfspr r25, 0x395 + mfspr r26, 0x396 + mfspr r27, 0x397 + mfspr r28, 0x398 + mfspr r29, 0x399 + mfspr r30, 0x39a + mfspr r31, 0x39b + stmw r20, 0x2fc(r2) + b lbl_80371340 + mfspr r16, 0x3a0 + mfspr r17, 0x3a7 + mfspr r18, 0x3a8 + mfspr r19, 0x3a9 + mfspr r20, 0x3aa + mfspr r21, 0x3ab + mfspr r22, 0x3ac + mfspr r23, 0x3ad + mfspr r24, 0x3ae + mfspr r25, 0x3af + mfspr r26, 0x3b0 + mfspr r27, 0x3b7 + mfspr r28, 0x3bf + mfspr r29, 0x3f6 + mfspr r30, 0x3f7 + mfspr r31, 0x3ff + stmw r16, 0x2b8(r2) + +lbl_80371340: + mfspr r19, 0x3f5 + mfspr r20, 0x3b9 + mfspr r21, 0x3ba + mfspr r22, 0x3bd + mfspr r23, 0x3be + mfspr r24, 0x3bb + mfspr r25, 0x3b8 + mfspr r26, 0x3bc + mfspr r27, 0x3fc + mfspr r28, 0x3fd + mfspr r29, 0x3fe + mfspr r30, 0x3FB + mfspr r31, 0x3f9 + stmw r19, 0x284(r2) + b end + + mfspr r25, 0x3d0 + mfspr r26, 0x3d1 + mfspr r27, 0x3d2 + mfspr r28, 0x3d3 + mfspr r29, 0x3D4 + mfspr r30, 0x3D5 + mfspr r31, 0x3d6 + stmw r25, 0x240(r2) + mfspr r31, 0x16 + stw r31, 0x278(r2) +end: + blr +#endif // clang-format on +} + +asm void TRKRestoreExtended1Block() +{ +#ifdef __MWERKS__ // clang-format off + nofralloc + lis r2, gTRKCPUState@h /* 0x8044F338@h */ + ori r2, r2, gTRKCPUState@l /* 0x8044F338@l */ + lis r5, gTRKRestoreFlags@h /* 0x803D3238@h */ + ori r5, r5, gTRKRestoreFlags@l /* 0x803D3238@l */ + lbz r3, 0(r5) + lbz r6, 1(r5) + li r0, 0 + stb r0, 0(r5) + stb r0, 1(r5) + cmpwi r3, 0 + beq lbl_803713E4 + lwz r24, 0x1e8(r2) + lwz r25, 0x1ec(r2) + mttbl r24 + mttbu r25 +lbl_803713E4: + lmw r20, 0x2fc(r2) + mtspr 0x390, r20 + mtspr 0x391, r21 + mtspr 0x392, r22 + mtspr 0x393, r23 + mtspr 0x394, r24 + mtspr 0x395, r25 + mtspr 0x396, r26 + mtspr 0x397, r27 + mtspr 0x398, r28 + mtspr 0x39a, r30 + mtspr 0x39b, r31 + b lbl_80371430 + lmw r26, 0x2e0(r2) + mtspr 0x3b0, r26 + mtspr 0x3b7, r27 + mtspr 0x3f6, r29 + mtspr 0x3f7, r30 + mtspr 0x3ff, r31 +lbl_80371430: + lmw r19, 0x284(r2) + mtspr 0x3f5, r19 + mtspr 0x3b9, r20 + mtspr 0x3ba, r21 + mtspr 0x3bd, r22 + mtspr 0x3be, r23 + mtspr 0x3bb, r24 + mtspr 0x3b8, r25 + mtspr 0x3bc, r26 + mtspr 0x3fc, r27 + mtspr 0x3fd, r28 + mtspr 0x3fe, r29 + mtspr 0x3FB, r30 + mtspr 0x3f9, r31 + b lbl_8037149C + cmpwi r6, 0 + beq lbl_8037147C + lwz r26, 0x278(r2) + mtspr 0x16, r26 +lbl_8037147C: + lmw r25, 0x240(r2) + mtspr 0x3d0, r25 + mtspr 0x3d1, r26 + mtspr 0x3d2, r27 + mtspr 0x3d3, r28 + mtspr 0x3D4, r29 + mtspr 0x3D5, r30 + mtspr 0x3d6, r31 +lbl_8037149C: + lmw r16, 0x1a8(r2) + mtsr 0, r16 + mtsr 1, r17 + mtsr 2, r18 + mtsr 3, r19 + mtsr 4, r20 + mtsr 5, r21 + mtsr 6, r22 + mtsr 7, r23 + mtsr 8, r24 + mtsr 9, r25 + mtsr 0xa, r26 + mtsr 0xb, r27 + mtsr 0xc, r28 + mtsr 0xd, r29 + mtsr 0xe, r30 + mtsr 0xf, r31 + lmw r12, 0x1f0(r2) + mtspr 0x3f0, r12 + mtspr 0x3f1, r13 + mtspr 0x1b, r14 + mtspr 0x11f, r15 + mtibatu 0, r16 + mtibatl 0, r17 + mtibatu 1, r18 + mtibatl 1, r19 + mtibatu 2, r20 + mtibatl 2, r21 + mtibatu 3, r22 + mtibatl 3, r23 + mtdbatu 0, r24 + mtdbatl 0, r25 + mtdbatu 1, r26 + mtdbatl 1, r27 + mtdbatu 2, r28 + mtdbatl 2, r29 + mtdbatu 3, r30 + mtdbatl 3, r31 + lmw r22, 0x25c(r2) + mtspr 0x19, r22 + mtdar r23 + mtdsisr r24 + mtspr 0x110, r25 + mtspr 0x111, r26 + mtspr 0x112, r27 + mtspr 0x113, r28 + mtspr 0x3f2, r30 + mtspr 0x11a, r31 + blr +#endif // clang-format on +} + +u32 TRKTargetCPUMinorType(void) { return 0x54; } diff --git a/src/TRK_MINNOW_DOLPHIN/msg.c b/src/TRK_MINNOW_DOLPHIN/msg.c new file mode 100644 index 00000000..0ae376eb --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/msg.c @@ -0,0 +1,9 @@ +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msg.h" +#include "TRK_MINNOW_DOLPHIN/Os/dolphin/dolphin_trk_glue.h" +#include "PowerPC_EABI_Support/MetroTRK/trk.h" + +DSError TRKMessageSend(TRK_Msg* msg) +{ + DSError write_err = TRKWriteUARTN(&msg->m_msg, msg->m_msgLength); + return DS_NoError; +} diff --git a/src/TRK_MINNOW_DOLPHIN/msgbuf.c b/src/TRK_MINNOW_DOLPHIN/msgbuf.c new file mode 100644 index 00000000..8eb7031c --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/msgbuf.c @@ -0,0 +1,359 @@ +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msgbuf.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/nubinit.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/mutex_TRK.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/mem_TRK.h" +#include "stddef.h" + +TRKBuffer gTRKMsgBufs[3]; + +void TRKSetBufferUsed(TRKBuffer* msg, BOOL state) { msg->isInUse = state; } + +DSError TRKInitializeMessageBuffers(void) +{ + int i; + for (i = 0; i < 3; i++) { + TRKInitializeMutex(&gTRKMsgBufs[i]); + TRKAcquireMutex(&gTRKMsgBufs[i]); + TRKSetBufferUsed(&gTRKMsgBufs[i], FALSE); + TRKReleaseMutex(&gTRKMsgBufs[i]); + } + + return DS_NoError; +} + +DSError TRKGetFreeBuffer(int* msgID, TRKBuffer** outMsg) +{ + TRKBuffer* buf; + DSError error = DS_NoMessageBufferAvailable; + int i; + + *outMsg = NULL; + + for (i = 0; i < 3; i++) { + buf = TRKGetBuffer(i); + + TRKAcquireMutex(buf); + if (!buf->isInUse) { + TRKResetBuffer(buf, TRUE); + TRKSetBufferUsed(buf, TRUE); + error = DS_NoError; + *outMsg = buf; + *msgID = i; + i = 3; // why not break? weird choice + } + TRKReleaseMutex(buf); + } + + return error; +} + +void* TRKGetBuffer(int idx) +{ + TRKBuffer* buf = NULL; + if (idx >= 0 && idx < 3) { + buf = &gTRKMsgBufs[idx]; + } + + return buf; +} + +void TRKReleaseBuffer(int idx) +{ + TRKBuffer* msg; + if (idx != -1 && idx >= 0 && idx < 3) { + msg = &gTRKMsgBufs[idx]; + TRKAcquireMutex(msg); + TRKSetBufferUsed(msg, FALSE); + TRKReleaseMutex(msg); + } +} + +void TRKResetBuffer(TRKBuffer* msg, BOOL keepData) +{ + msg->length = 0; + msg->position = 0; + + if (!keepData) { + TRK_memset(msg->data, 0, TRKMSGBUF_SIZE); + } +} + +DSError TRKSetBufferPosition(TRKBuffer* msg, u32 pos) +{ + DSError error = DS_NoError; + + if (pos > 0x880) { + error = DS_MessageBufferOverflow; + } else { + msg->position = pos; + // If the new position is past the current length, + // update the length + if (pos > msg->length) { + msg->length = pos; + } + } + + return error; +} + +DSError TRKAppendBuffer(TRKBuffer* msg, const void* data, size_t length) +{ + DSError error = DS_NoError; // r31 + u32 bytesLeft; + + // Return if no bytes to append + if (length == 0) { + return DS_NoError; + } + + bytesLeft = 0x880 - msg->position; + + // If there isn't enough space left in the buffer, change the number + // of bytes to append to the remaning number of bytes + if (bytesLeft < length) { + error = DS_MessageBufferOverflow; + length = bytesLeft; + } + + if (length == 1) { + // If the length of bytes to append is 1, just copy the byte over + msg->data[msg->position] = ((u8*)data)[0]; + } else { + // Otherwise, use memcpy + TRK_memcpy(msg->data + msg->position, data, length); + } + + // Update the position and length + msg->position += length; + msg->length = msg->position; + + return error; +} + +DSError TRKReadBuffer(TRKBuffer* msg, void* data, size_t length) +{ + DSError error = DS_NoError; + unsigned int + bytesLeft; // this has to be unsigned int not u32 to match lmfao. + + // Return if no bytes to read + if (length == 0) { + return DS_NoError; + } + + bytesLeft = msg->length - msg->position; + + // If the number of bytes to read exceeds the buffer length, change + // the length to the remaining number of bytes + if (length > bytesLeft) { + error = DS_MessageBufferReadError; + length = bytesLeft; + } + + TRK_memcpy(data, msg->data + msg->position, length); + msg->position += length; + return error; +} + +DSError TRKAppendBuffer1_ui16(TRKBuffer* buffer, const u16 data) +{ + u8* bigEndianData; + u8* byteData; + u8 swapBuffer[sizeof(data)]; + + if (gTRKBigEndian) { + bigEndianData = (u8*)&data; + } else { + byteData = (u8*)&data; + bigEndianData = swapBuffer; + + bigEndianData[0] = byteData[1]; + bigEndianData[1] = byteData[0]; + } + + return TRKAppendBuffer(buffer, (const void*)bigEndianData, sizeof(data)); +} + +DSError TRKAppendBuffer1_ui32(TRKBuffer* buffer, const u32 data) +{ + u8* bigEndianData; + u8* byteData; + u8 swapBuffer[sizeof(data)]; + + if (gTRKBigEndian) { + bigEndianData = (u8*)&data; + } else { + byteData = (u8*)&data; + bigEndianData = swapBuffer; + + bigEndianData[0] = byteData[3]; + bigEndianData[1] = byteData[2]; + bigEndianData[2] = byteData[1]; + bigEndianData[3] = byteData[0]; + } + + return TRKAppendBuffer(buffer, (const void*)bigEndianData, sizeof(data)); +} + +DSError TRKAppendBuffer1_ui64(TRKBuffer* buffer, const u64 data) +{ + u8* bigEndianData; + u8* byteData; + u8 swapBuffer[sizeof(data)]; + if (gTRKBigEndian) { + bigEndianData = (u8*)&data; + } else { + byteData = (u8*)&data; + bigEndianData = swapBuffer; + + bigEndianData[0] = byteData[7]; + bigEndianData[1] = byteData[6]; + bigEndianData[2] = byteData[5]; + bigEndianData[3] = byteData[4]; + bigEndianData[4] = byteData[3]; + bigEndianData[5] = byteData[2]; + bigEndianData[6] = byteData[1]; + bigEndianData[7] = byteData[0]; + } + + return TRKAppendBuffer(buffer, (const void*)bigEndianData, sizeof(data)); +} + +DSError TRKAppendBuffer_ui8(TRKBuffer* buffer, const u8* data, int count) +{ + DSError err; + int i; + + for (i = 0, err = DS_NoError; err == DS_NoError && i < count; i++) { + err = TRKAppendBuffer1_ui8(buffer, data[i]); + } + + return err; +} + +DSError TRKAppendBuffer_ui32(TRKBuffer* buffer, const u32* data, int count) +{ + DSError err; + int i; + + for (i = 0, err = DS_NoError; err == DS_NoError && i < count; i++) { + err = TRKAppendBuffer1_ui32(buffer, data[i]); + } + + return err; +} + +DSError TRKReadBuffer1_ui8(TRKBuffer* buffer, u8* data) +{ + return TRKReadBuffer(buffer, (void*)data, 1); +} + +DSError TRKReadBuffer1_ui16(TRKBuffer* buffer, u16* data) +{ + DSError err; + + u8* bigEndianData; + u8* byteData; + u8 swapBuffer[sizeof(data)]; + + if (gTRKBigEndian) { + bigEndianData = (u8*)data; + } else { + bigEndianData = swapBuffer; + } + + err = TRKReadBuffer(buffer, (void*)bigEndianData, sizeof(*data)); + + if (!gTRKBigEndian && err == DS_NoError) { + byteData = (u8*)data; + + byteData[0] = bigEndianData[1]; + byteData[1] = bigEndianData[0]; + } + + return err; +} + +DSError TRKReadBuffer1_ui32(TRKBuffer* buffer, u32* data) +{ + DSError err; + + u8* bigEndianData; + u8* byteData; + u8 swapBuffer[sizeof(data)]; + + if (gTRKBigEndian) { + bigEndianData = (u8*)data; + } else { + bigEndianData = swapBuffer; + } + + err = TRKReadBuffer(buffer, (void*)bigEndianData, sizeof(*data)); + + if (!gTRKBigEndian && err == DS_NoError) { + byteData = (u8*)data; + + byteData[0] = bigEndianData[3]; + byteData[1] = bigEndianData[2]; + byteData[2] = bigEndianData[1]; + byteData[3] = bigEndianData[0]; + } + + return err; +} + +DSError TRKReadBuffer1_ui64(TRKBuffer* buffer, u64* data) +{ + DSError err; + + u8* bigEndianData; + u8* byteData; + u8 swapBuffer[sizeof(data)]; + + if (gTRKBigEndian) { + bigEndianData = (u8*)data; + } else { + bigEndianData = swapBuffer; + } + + err = TRKReadBuffer(buffer, (void*)bigEndianData, sizeof(*data)); + + if (!gTRKBigEndian && err == 0) { + byteData = (u8*)data; + + byteData[0] = bigEndianData[7]; + byteData[1] = bigEndianData[6]; + byteData[2] = bigEndianData[5]; + byteData[3] = bigEndianData[4]; + byteData[4] = bigEndianData[3]; + byteData[5] = bigEndianData[2]; + byteData[6] = bigEndianData[1]; + byteData[7] = bigEndianData[0]; + } + + return err; +} + +DSError TRKReadBuffer_ui8(TRKBuffer* buffer, u8* data, int count) +{ + DSError err; + int i; + + for (i = 0, err = DS_NoError; err == DS_NoError && i < count; i++) { + err = TRKReadBuffer1_ui8(buffer, &(data[i])); + } + + return err; +} + +DSError TRKReadBuffer_ui32(TRKBuffer* buffer, u32* data, int count) +{ + DSError err; + s32 i; + + for (i = 0, err = DS_NoError; err == DS_NoError && i < count; i++) { + err = TRKReadBuffer1_ui32(buffer, &(data[i])); + } + + return err; +} diff --git a/src/TRK_MINNOW_DOLPHIN/msghndlr.c b/src/TRK_MINNOW_DOLPHIN/msghndlr.c new file mode 100644 index 00000000..35c91822 --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/msghndlr.c @@ -0,0 +1,689 @@ +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msghndlr.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/nubevent.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msgbuf.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msg.h" +#include "TRK_MINNOW_DOLPHIN/Os/dolphin/targcont.h" +#include "TRK_MINNOW_DOLPHIN/ppc/Generic/targimpl.h" +#include "PowerPC_EABI_Support/MetroTRK/trk.h" + +BOOL IsTRKConnected; + +BOOL GetTRKConnected() +{ + return IsTRKConnected; +} + +void SetTRKConnected(BOOL connected) +{ + IsTRKConnected = connected; +} + +static void TRKMessageIntoReply(TRKBuffer* buffer, u8 ackCmd, + DSReplyError errSentInAck) +{ + TRKResetBuffer(buffer, 1); + + TRKAppendBuffer1_ui8(buffer, ackCmd); + TRKAppendBuffer1_ui8(buffer, errSentInAck); +} + +DSError TRKSendACK(TRKBuffer* buffer) +{ + DSError err; + int ackTries; + + ackTries = 3; + do { + err = TRKMessageSend((TRK_Msg*)buffer); + --ackTries; + } while (err != DS_NoError && ackTries > 0); + + return err; +} + +DSError TRKStandardACK(TRKBuffer* buffer, MessageCommandID commandID, + DSReplyError replyError) +{ + TRKMessageIntoReply(buffer, commandID, replyError); + TRKSendACK(buffer); + return; +} + +DSError TRKDoUnsupported(TRKBuffer* buffer) +{ + return TRKStandardACK(buffer, DSMSG_ReplyACK, + DSREPLY_UnsupportedCommandError); +} + +DSError TRKDoConnect(TRKBuffer* buffer) +{ + SetTRKConnected(TRUE); + return TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_NoError); +} + +DSError TRKDoDisconnect(TRKBuffer* buffer) +{ + DSError error = DS_NoError; + TRKEvent event; + SetTRKConnected(FALSE); + + if ((error = TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_NoError)) + == DS_NoError) { + TRKConstructEvent(&event, 1); + TRKPostEvent(&event); + } + return error; +} + +DSError TRKDoReset(TRKBuffer* buffer) +{ + TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_NoError); + __TRK_reset(); + return DS_NoError; +} + +DSError TRKDoVersions(TRKBuffer* buffer) +{ + DSError error; + DSVersions versions; + + if (buffer->length != 1) { + error = TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_PacketSizeError); + } else { + TRKMessageIntoReply(buffer, DSMSG_ReplyACK, DSREPLY_NoError); + error = TRKTargetVersions(&versions); + + if (error == DS_NoError) + error = TRKAppendBuffer1_ui8(buffer, versions.kernelMajor); + if (error == DS_NoError) + error = TRKAppendBuffer1_ui8(buffer, versions.kernelMinor); + if (error == DS_NoError) + error = TRKAppendBuffer1_ui8(buffer, versions.protocolMajor); + if (error == DS_NoError) + error = TRKAppendBuffer1_ui8(buffer, versions.protocolMinor); + + if (error != DS_NoError) + error = TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_CWDSError); + else + error = TRKSendACK(buffer); + } + return error; +} + +DSError TRKDoSupportMask(TRKBuffer* buffer) +{ + DSError error; + u8 mask[32]; + + if (buffer->length != 1) { + TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_PacketSizeError); + } else { + TRKMessageIntoReply(buffer, DSMSG_ReplyACK, DSREPLY_NoError); + error = TRKTargetSupportMask(mask); + + if (error == DS_NoError) + error = TRKAppendBuffer(buffer, mask, 32); + if (error == DS_NoError) + error = TRKAppendBuffer1_ui8(buffer, 2); + + if (error != DS_NoError) + TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_CWDSError); + else + TRKSendACK(buffer); + } +} + +DSError TRKDoCPUType(TRKBuffer* buffer) +{ + DSError error; + DSCPUType cputype; + + if (buffer->length != 1) { + error = TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_PacketSizeError); + return error; + } + + TRKMessageIntoReply(buffer, DSMSG_ReplyACK, DSREPLY_NoError); + + error = TRKTargetCPUType(&cputype); + + if (error == DS_NoError) + error = TRKAppendBuffer1_ui8(buffer, cputype.cpuMajor); + if (error == DS_NoError) + error = TRKAppendBuffer1_ui8(buffer, cputype.cpuMinor); + if (error == DS_NoError) + error = TRKAppendBuffer1_ui8(buffer, cputype.bigEndian); + if (error == DS_NoError) + error = TRKAppendBuffer1_ui8(buffer, cputype.defaultTypeSize); + if (error == DS_NoError) + error = TRKAppendBuffer1_ui8(buffer, cputype.fpTypeSize); + if (error == DS_NoError) + error = TRKAppendBuffer1_ui8(buffer, cputype.extended1TypeSize); + if (error == DS_NoError) + error = TRKAppendBuffer1_ui8(buffer, cputype.extended2TypeSize); + + if (error != DS_NoError) + error = TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_CWDSError); + else + error = TRKSendACK(buffer); + + return error; +} + +DSError TRKDoReadMemory(TRKBuffer* buffer) +{ + DSError error; + DSReplyError replyError; + u8 tempBuf[0x800]; + u32 length; + u32 msg_start; + u16 msg_length; + u8 msg_options; + u8 msg_command; + + if (buffer->length != 8) { + error = TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_PacketSizeError); + return error; + } + + TRKSetBufferPosition(buffer, DSREPLY_NoError); + error = TRKReadBuffer1_ui8(buffer, &msg_command); + if (error == DS_NoError) + error = TRKReadBuffer1_ui8(buffer, &msg_options); + + if (error == DS_NoError) + error = TRKReadBuffer1_ui16(buffer, &msg_length); + + if (error == DS_NoError) + error = TRKReadBuffer1_ui32(buffer, &msg_start); + + if (msg_options & 2) { + error = TRKStandardACK(buffer, DSMSG_ReplyACK, + DSREPLY_UnsupportedOptionError); + return error; + } + + if (msg_length > 0x800) { + error = TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_ParameterError); + return error; + } + + TRKMessageIntoReply(buffer, DSMSG_ReplyACK, DSREPLY_NoError); + + if (error == DS_NoError) { + length = (u32)msg_length; + error = TRKTargetAccessMemory( + tempBuf, msg_start, &length, + (msg_options & 8) ? MEMACCESS_UserMemory : MEMACCESS_DebuggerMemory, + 1); + msg_length = (u16)length; + if (error == DS_NoError) + error = TRKAppendBuffer1_ui16(buffer, msg_length); + if (error == DS_NoError) + error = TRKAppendBuffer(buffer, tempBuf, length); + } + + if (error != DS_NoError) { + switch (error) { + case DS_CWDSException: + replyError = DSREPLY_CWDSException; + break; + case DS_InvalidMemory: + replyError = DSREPLY_InvalidMemoryRange; + break; + case DS_InvalidProcessID: + replyError = DSREPLY_InvalidProcessID; + break; + case DS_InvalidThreadID: + replyError = DSREPLY_InvalidThreadID; + break; + case DS_OSError: + replyError = DSREPLY_OSError; + break; + default: + replyError = DSREPLY_CWDSError; + break; + } + error = TRKStandardACK(buffer, DSMSG_ReplyACK, replyError); + } else { + error = TRKSendACK(buffer); + } + + return error; +} + +DSError TRKDoWriteMemory(TRKBuffer* buffer) +{ + DSError error; + DSReplyError replyError; + u8 tmpBuffer[0x800]; + u32 length; + u32 msg_start; + u16 msg_length; + u8 msg_options; + u8 msg_command; + + if (buffer->length <= 8) { + error = TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_PacketSizeError); + return error; + } + + TRKSetBufferPosition(buffer, DSREPLY_NoError); + error = TRKReadBuffer1_ui8(buffer, &msg_command); + if (error == DS_NoError) + error = TRKReadBuffer1_ui8(buffer, &msg_options); + + if (error == DS_NoError) + error = TRKReadBuffer1_ui16(buffer, &msg_length); + + if (error == DS_NoError) + error = TRKReadBuffer1_ui32(buffer, &msg_start); + + if (msg_options & 2) { + error = TRKStandardACK(buffer, DSMSG_ReplyACK, + DSREPLY_UnsupportedOptionError); + return error; + } + + if ((buffer->length != msg_length + 8) || (msg_length > 0x800)) { + error = TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_ParameterError); + } else { + if (error == DS_NoError) { + length = (u32)msg_length; + error = TRKReadBuffer(buffer, tmpBuffer, length); + if (error == DS_NoError) { + error = TRKTargetAccessMemory(tmpBuffer, msg_start, &length, + (msg_options & 8) + ? MEMACCESS_UserMemory + : MEMACCESS_DebuggerMemory, + FALSE); + } + msg_length = (u16)length; + } + + if (error == DS_NoError) + TRKMessageIntoReply(buffer, DSMSG_ReplyACK, DSREPLY_NoError); + + if (error == DS_NoError) + error = TRKAppendBuffer1_ui16(buffer, msg_length); + + if (error != DS_NoError) { + switch (error) { + case DS_CWDSException: + replyError = DSREPLY_CWDSException; + break; + case DS_InvalidMemory: + replyError = DSREPLY_InvalidMemoryRange; + break; + case DS_InvalidProcessID: + replyError = DSREPLY_InvalidProcessID; + break; + case DS_InvalidThreadID: + replyError = DSREPLY_InvalidThreadID; + break; + case DS_OSError: + replyError = DSREPLY_OSError; + break; + default: + replyError = DSREPLY_CWDSError; + break; + } + error = TRKStandardACK(buffer, DSMSG_ReplyACK, replyError); + } else { + error = TRKSendACK(buffer); + } + } + + return error; +} + +DSError TRKDoReadRegisters(TRKBuffer* buffer) +{ + DSError error; + DSReplyError replyError; + DSMessageRegisterOptions options; + u32 registerDataLength; + u16 msg_lastRegister; + u16 msg_firstRegister; + u8 msg_options; + u8 msg_command; + + if (buffer->length != 6) { + error = TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_PacketSizeError); + return error; + } + TRKSetBufferPosition(buffer, DSREPLY_NoError); + error = TRKReadBuffer1_ui8(buffer, &msg_command); + if (error == DS_NoError) + error = TRKReadBuffer1_ui8(buffer, &msg_options); + + if (error == DS_NoError) + error = TRKReadBuffer1_ui16(buffer, &msg_firstRegister); + + if (error == DS_NoError) + error = TRKReadBuffer1_ui16(buffer, &msg_lastRegister); + + if (msg_firstRegister > msg_lastRegister) { + error = TRKStandardACK(buffer, DSMSG_ReplyACK, + DSREPLY_InvalidRegisterRange); + return error; + } + + if (error == DS_NoError) + TRKMessageIntoReply(buffer, DSMSG_ReplyACK, DSREPLY_NoError); + + options = (DSMessageRegisterOptions)msg_options; + switch (options) { + case DSREG_Default: + error = TRKTargetAccessDefault(msg_firstRegister, msg_lastRegister, + buffer, ®isterDataLength, TRUE); + break; + case DSREG_FP: + error = TRKTargetAccessFP(msg_firstRegister, msg_lastRegister, buffer, + ®isterDataLength, TRUE); + break; + case DSREG_Extended1: + error = TRKTargetAccessExtended1(msg_firstRegister, msg_lastRegister, + buffer, ®isterDataLength, TRUE); + break; + case DSREG_Extended2: + error = TRKTargetAccessExtended2(msg_firstRegister, msg_lastRegister, + buffer, ®isterDataLength, TRUE); + break; + default: + error = DS_UnsupportedError; + break; + } + + if (error != DS_NoError) { + switch (error) { + case DS_UnsupportedError: + replyError = DSREPLY_UnsupportedOptionError; + break; + case DS_InvalidRegister: + replyError = DSREPLY_InvalidRegisterRange; + break; + case DS_CWDSException: + replyError = DSREPLY_CWDSException; + break; + case DS_InvalidProcessID: + replyError = DSREPLY_InvalidProcessID; + break; + case DS_InvalidThreadID: + replyError = DSREPLY_InvalidThreadID; + break; + case DS_OSError: + replyError = DSREPLY_OSError; + break; + default: + replyError = DSREPLY_CWDSError; + } + + error = TRKStandardACK(buffer, DSMSG_ReplyACK, replyError); + } else { + error = TRKSendACK(buffer); + } + + return error; +} + +DSError TRKDoWriteRegisters(TRKBuffer* buffer) +{ + DSError error; + DSReplyError replyError; + DSMessageRegisterOptions options; + u32 registerDataLength; + u16 msg_lastRegister; + u16 msg_firstRegister; + u8 msg_options; + u8 msg_command; + + if (buffer->length <= 6) { + error = TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_PacketSizeError); + return error; + } + TRKSetBufferPosition(buffer, DSREPLY_NoError); + error = TRKReadBuffer1_ui8(buffer, &msg_command); + if (error == DS_NoError) + error = TRKReadBuffer1_ui8(buffer, &msg_options); + + if (error == DS_NoError) + error = TRKReadBuffer1_ui16(buffer, &msg_firstRegister); + + if (error == DS_NoError) + error = TRKReadBuffer1_ui16(buffer, &msg_lastRegister); + + if (msg_firstRegister > msg_lastRegister) { + error = TRKStandardACK(buffer, DSMSG_ReplyACK, + DSREPLY_InvalidRegisterRange); + return error; + } + + options = (DSMessageRegisterOptions)msg_options; + switch (options) { + case DSREG_Default: + error = TRKTargetAccessDefault(msg_firstRegister, msg_lastRegister, + buffer, ®isterDataLength, FALSE); + break; + case DSREG_FP: + error = TRKTargetAccessFP(msg_firstRegister, msg_lastRegister, buffer, + ®isterDataLength, FALSE); + break; + case DSREG_Extended1: + error = TRKTargetAccessExtended1(msg_firstRegister, msg_lastRegister, + buffer, ®isterDataLength, FALSE); + break; + case DSREG_Extended2: + error = TRKTargetAccessExtended2(msg_firstRegister, msg_lastRegister, + buffer, ®isterDataLength, FALSE); + break; + default: + error = DS_UnsupportedError; + break; + } + + if (error == DS_NoError) + TRKMessageIntoReply(buffer, DSMSG_ReplyACK, DSREPLY_NoError); + + if (error != DS_NoError) { + switch (error) { + case DS_UnsupportedError: + replyError = DSREPLY_UnsupportedOptionError; + break; + case DS_InvalidRegister: + replyError = DSREPLY_InvalidRegisterRange; + break; + case DS_MessageBufferReadError: + replyError = DSREPLY_PacketSizeError; + break; + case DS_CWDSException: + replyError = DSREPLY_CWDSException; + break; + case DS_InvalidProcessID: + replyError = DSREPLY_InvalidProcessID; + break; + case DS_InvalidThreadID: + replyError = DSREPLY_InvalidThreadID; + break; + case DS_OSError: + replyError = DSREPLY_OSError; + break; + default: + replyError = DSREPLY_CWDSError; + } + + error = TRKStandardACK(buffer, DSMSG_ReplyACK, replyError); + } else { + error = TRKSendACK(buffer); + } + + return error; +} + +DSError TRKDoFlushCache(TRKBuffer* buffer) +{ + DSError error; + DSReplyError replyErr; + u32 msg_end; + u32 msg_start; + u8 msg_options; + u8 msg_command; + + if (buffer->length != 10) { + error = TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_PacketSizeError); + return error; + } + + TRKSetBufferPosition(buffer, DSREPLY_NoError); + error = TRKReadBuffer1_ui8(buffer, &msg_command); + if (error == DS_NoError) + error = TRKReadBuffer1_ui8(buffer, &msg_options); + if (error == DS_NoError) + error = TRKReadBuffer1_ui32(buffer, &msg_start); + if (error == DS_NoError) + error = TRKReadBuffer1_ui32(buffer, &msg_end); + + if (msg_start > msg_end) { + error = TRKStandardACK(buffer, DSMSG_ReplyACK, + DSREPLY_InvalidMemoryRange); + return error; + } + + if (error == DS_NoError) + error = TRKTargetFlushCache(msg_options, (void*)msg_start, + (void*)msg_end); + + if (error == DS_NoError) + TRKMessageIntoReply(buffer, DSMSG_ReplyACK, DSREPLY_NoError); + + if (error != DS_NoError) { + switch (error) { + case DS_UnsupportedError: + replyErr = DSREPLY_UnsupportedOptionError; + break; + default: + replyErr = DSREPLY_CWDSError; + break; + } + + error = TRKStandardACK(buffer, DSMSG_ReplyACK, replyErr); + } else { + error = TRKSendACK(buffer); + } + + return error; +} + +DSError TRKDoContinue(TRKBuffer* buffer) +{ + DSError error; + + error = TRKTargetStopped(); + if (error == DS_NoError) { + error = TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_NotStopped); + return error; + } + + error = TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_NoError); + if (error == DS_NoError) + error = TRKTargetContinue(); + + return error; +} + +DSError TRKDoStep(TRKBuffer* buffer) +{ + DSError error; + u8 msg_command; + u8 msg_options; + u8 msg_count; + u32 msg_rangeStart; + u32 msg_rangeEnd; + u32 pc; + + if (buffer->length < 3) + return TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_PacketSizeError); + + TRKSetBufferPosition(buffer, DSREPLY_NoError); + + error = TRKReadBuffer1_ui8(buffer, &msg_command); + if (error == DS_NoError) + error = TRKReadBuffer1_ui8(buffer, &msg_options); + + switch (msg_options) { + case DSSTEP_IntoCount: + case DSSTEP_OverCount: + if (error == DS_NoError) + TRKReadBuffer1_ui8(buffer, &msg_count); + if (msg_count >= 1) { + break; + } + return TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_ParameterError); + case DSSTEP_IntoRange: + case DSSTEP_OverRange: + if (buffer->length != 10) + return TRKStandardACK(buffer, DSMSG_ReplyACK, + DSREPLY_PacketSizeError); + + if (error == DS_NoError) + error = TRKReadBuffer1_ui32(buffer, &msg_rangeStart); + if (error == DS_NoError) + error = TRKReadBuffer1_ui32(buffer, &msg_rangeEnd); + + pc = TRKTargetGetPC(); + if (pc >= msg_rangeStart && pc <= msg_rangeEnd) { + break; + } + return TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_ParameterError); + default: + return TRKStandardACK(buffer, DSMSG_ReplyACK, + DSREPLY_UnsupportedOptionError); + } + + if (!TRKTargetStopped()) { + return TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_NotStopped); + } else { + error = TRKStandardACK(buffer, DSMSG_ReplyACK, DSREPLY_NoError); + if (error == DS_NoError) + switch (msg_options) { + case DSSTEP_IntoCount: + case DSSTEP_OverCount: + error = TRKTargetSingleStep(msg_count, + (msg_options == DSSTEP_OverCount)); + break; + case DSSTEP_IntoRange: + case DSSTEP_OverRange: + error = TRKTargetStepOutOfRange( + msg_rangeStart, msg_rangeEnd, + (msg_options == DSSTEP_OverRange)); + break; + } + + return error; + } +} + +DSError TRKDoStop(TRKBuffer* b) +{ + DSReplyError replyError; + + switch (TRKTargetStop()) { + case DS_NoError: + replyError = DSREPLY_NoError; + break; + case DS_InvalidProcessID: + replyError = DSREPLY_InvalidProcessID; + break; + case DS_InvalidThreadID: + replyError = DSREPLY_InvalidThreadID; + break; + case DS_OSError: + replyError = DSREPLY_OSError; + break; + default: + replyError = DSREPLY_Error; + break; + } + + return TRKStandardACK(b, DSMSG_ReplyACK, replyError); +} diff --git a/src/TRK_MINNOW_DOLPHIN/mutex_TRK.c b/src/TRK_MINNOW_DOLPHIN/mutex_TRK.c new file mode 100644 index 00000000..37e09501 --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/mutex_TRK.c @@ -0,0 +1,7 @@ +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/mutex_TRK.h" + +DSError TRKInitializeMutex(void*) { return DS_NoError; } + +DSError TRKAcquireMutex(void*) { return DS_NoError; } + +DSError TRKReleaseMutex(void*) { return DS_NoError; } diff --git a/src/TRK_MINNOW_DOLPHIN/notify.c b/src/TRK_MINNOW_DOLPHIN/notify.c new file mode 100644 index 00000000..7dce4537 --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/notify.c @@ -0,0 +1,40 @@ +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/notify.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msgbuf.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/support.h" +#include "TRK_MINNOW_DOLPHIN/ppc/Generic/targimpl.h" +#include "PowerPC_EABI_Support/MetroTRK/trk.h" + +DSError TRKDoNotifyStopped(MessageCommandID cmd) +{ + DSError err; + int reqIdx; + int bufIdx; + TRKBuffer* msg; + + err = TRKGetFreeBuffer(&bufIdx, &msg); + if (err == DS_NoError) { + if (msg->position >= 0x880) { + err = DS_MessageBufferOverflow; + } else { + msg->data[msg->position++] = cmd; + ++msg->length; + err = 0; + } + + if (err == DS_NoError) { + if (cmd == DSMSG_NotifyStopped) { + TRKTargetAddStopInfo(msg); + } else { + TRKTargetAddExceptionInfo(msg); + } + } + + err = TRKRequestSend(msg, &reqIdx, 2, 3, 1); + if (err == DS_NoError) { + TRKReleaseBuffer(reqIdx); + } + TRKReleaseBuffer(bufIdx); + } + + return err; +} diff --git a/src/TRK_MINNOW_DOLPHIN/nubevent.c b/src/TRK_MINNOW_DOLPHIN/nubevent.c new file mode 100644 index 00000000..a35a43cd --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/nubevent.c @@ -0,0 +1,72 @@ +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/nubevent.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/mutex_TRK.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msgbuf.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/mem_TRK.h" + +TRKEventQueue gTRKEventQueue; + +DSError TRKInitializeEventQueue() +{ + TRKInitializeMutex(&gTRKEventQueue); + TRKAcquireMutex(&gTRKEventQueue); + gTRKEventQueue.count = 0; + gTRKEventQueue.next = 0; + gTRKEventQueue.eventID = 0x100; + TRKReleaseMutex(&gTRKEventQueue); + return DS_NoError; +} + +void TRKCopyEvent(TRKEvent* dstEvent, const TRKEvent* srcEvent) +{ + TRK_memcpy(dstEvent, srcEvent, sizeof(TRKEvent)); +} + +BOOL TRKGetNextEvent(TRKEvent* event) +{ + BOOL status = 0; + TRKAcquireMutex(&gTRKEventQueue); + if (0 < gTRKEventQueue.count) { + TRKCopyEvent(event, &gTRKEventQueue.events[gTRKEventQueue.next]); + gTRKEventQueue.count--; + gTRKEventQueue.next++; + if (gTRKEventQueue.next == 2) + gTRKEventQueue.next = 0; + + status = 1; + } + TRKReleaseMutex(&gTRKEventQueue); + return status; +} + +DSError TRKPostEvent(TRKEvent* event) +{ + DSError ret = DS_NoError; + int nextEventID; + + TRKAcquireMutex(&gTRKEventQueue); + + if (gTRKEventQueue.count == 2) { + ret = DS_EventQueueFull; + } else { + nextEventID = (gTRKEventQueue.next + gTRKEventQueue.count) % 2; + TRKCopyEvent(&gTRKEventQueue.events[nextEventID], event); + gTRKEventQueue.events[nextEventID].eventID = gTRKEventQueue.eventID; + gTRKEventQueue.eventID++; + if (gTRKEventQueue.eventID < 0x100) + gTRKEventQueue.eventID = 0x100; + + gTRKEventQueue.count++; + } + + TRKReleaseMutex(&gTRKEventQueue); + return ret; +} + +void TRKConstructEvent(TRKEvent* event, NubEventType eventType) +{ + event->eventType = eventType; + event->eventID = 0; + event->msgBufID = -1; +} + +void TRKDestructEvent(TRKEvent* event) { TRKReleaseBuffer(event->msgBufID); } diff --git a/src/TRK_MINNOW_DOLPHIN/nubinit.c b/src/TRK_MINNOW_DOLPHIN/nubinit.c new file mode 100644 index 00000000..fc08e85e --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/nubinit.c @@ -0,0 +1,80 @@ +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/nubinit.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/nubevent.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msgbuf.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/serpoll.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/dispatch.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/serpoll.h" +#include "TRK_MINNOW_DOLPHIN/Os/dolphin/dolphin_trk.h" +#include "TRK_MINNOW_DOLPHIN/Os/dolphin/dolphin_trk_glue.h" +#include "TRK_MINNOW_DOLPHIN/Os/dolphin/usr_put.h" +#include "TRK_MINNOW_DOLPHIN/ppc/Generic/targimpl.h" + +BOOL gTRKBigEndian; + +BOOL TRKInitializeEndian(void); + +DSError TRKInitializeNub(void) +{ + DSError ret; + DSError uartErr; + + ret = TRKInitializeEndian(); + + if (ret == DS_NoError) + usr_put_initialize(); + if (ret == DS_NoError) + ret = TRKInitializeEventQueue(); + if (ret == DS_NoError) + ret = TRKInitializeMessageBuffers(); + if (ret == DS_NoError) + ret = TRKInitializeDispatcher(); + + if (ret == DS_NoError) { + uartErr = TRKInitializeIntDrivenUART(0x0000e100, 1, 0, + (volatile u8**)&gTRKInputPendingPtr); + TRKTargetSetInputPendingPtr(gTRKInputPendingPtr); + if (uartErr != DS_NoError) { + ret = uartErr; + } + } + + if (ret == DS_NoError) + ret = TRKInitializeSerialHandler(); + if (ret == DS_NoError) + ret = TRKInitializeTarget(); + + return ret; +} + +DSError TRKTerminateNub(void) +{ + TRKTerminateSerialHandler(); + return DS_NoError; +} + +void TRKNubWelcome(void) +{ + TRK_board_display("MetroTRK for GAMECUBE v0.10"); + return; +} + +BOOL TRKInitializeEndian(void) +{ + u8 bendian[4]; + BOOL result = FALSE; + gTRKBigEndian = TRUE; + + bendian[0] = 0x12; + bendian[1] = 0x34; + bendian[2] = 0x56; + bendian[3] = 0x78; + + if (*(u32*)bendian == 0x12345678) { + gTRKBigEndian = TRUE; + } else if (*(u32*)bendian == 0x78563412) { + gTRKBigEndian = FALSE; + } else { + result = TRUE; + } + return result; +} diff --git a/src/TRK_MINNOW_DOLPHIN/serpoll.c b/src/TRK_MINNOW_DOLPHIN/serpoll.c new file mode 100644 index 00000000..831644fa --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/serpoll.c @@ -0,0 +1,82 @@ +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/serpoll.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/nubevent.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msgbuf.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msghndlr.h" +#include "TRK_MINNOW_DOLPHIN/Os/dolphin/dolphin_trk_glue.h" +#include "PowerPC_EABI_Support/MetroTRK/trk.h" + +static TRKFramingState gTRKFramingState; + +void* gTRKInputPendingPtr; + +MessageBufferID TRKTestForPacket() +{ + int bytes; + int batch; + int err; + TRKBuffer* b; + int id; + + bytes = TRKPollUART(); + if (bytes > 0) { + TRKGetFreeBuffer(&id, &b); + if (bytes > TRKMSGBUF_SIZE) { + for (; bytes > 0; bytes -= batch) { + batch = bytes > TRKMSGBUF_SIZE ? TRKMSGBUF_SIZE : bytes; + TRKReadUARTN(b->data, batch); + } + TRKStandardACK(b, 0xff, 6); + } else { + err = TRKReadUARTN(b->data, bytes); + if (err == 0) { + b->length = bytes; + return id; + } + } + } + if (id != -1) { + TRKReleaseBuffer(id); + } + return -1; +} + +void TRKGetInput(void) +{ + MessageBufferID id; + TRKBuffer* msgBuffer; + u8 command; + + id = TRKTestForPacket(); + if (id == -1) + return; + + msgBuffer = TRKGetBuffer(id); + TRKSetBufferPosition(msgBuffer, 0); + TRKReadBuffer1_ui8(msgBuffer, &command); + if (command < DSMSG_ReplyACK) { + TRKProcessInput(id); + } else { + TRKReleaseBuffer(id); + } +} + +void TRKProcessInput(int bufferIdx) +{ + TRKEvent event; + + TRKConstructEvent(&event, NUBEVENT_Request); + gTRKFramingState.msgBufID = -1; + event.msgBufID = bufferIdx; + TRKPostEvent(&event); +} + +DSError TRKInitializeSerialHandler(void) +{ + gTRKFramingState.msgBufID = -1; + gTRKFramingState.receiveState = DSRECV_Wait; + gTRKFramingState.isEscape = FALSE; + + return DS_NoError; +} + +DSError TRKTerminateSerialHandler(void) { return DS_NoError; } diff --git a/src/TRK_MINNOW_DOLPHIN/support.c b/src/TRK_MINNOW_DOLPHIN/support.c new file mode 100644 index 00000000..0d31ca10 --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/support.c @@ -0,0 +1,177 @@ +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/support.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msgbuf.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msg.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/serpoll.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msghndlr.h" +#include "stddef.h" +#include "string.h" + +DSError TRKSuppAccessFile(u32 file_handle, u8* data, size_t* count, + DSIOResult* io_result, BOOL need_reply, BOOL read) +{ + DSError error; + int replyBufferId; + TRKBuffer* replyBuffer; + int bufferId; + TRKBuffer* buffer; + u32 length; + u32 done; + u8 replyIOResult; + u16 replyLength; + BOOL exit; + + if (data == NULL || *count == 0) { + return DS_ParameterError; + } + + exit = FALSE; + *io_result = DS_IONoError; + done = 0; + error = DS_NoError; + while (!exit && done < *count && error == DS_NoError && *io_result == 0) { + if (*count - done > 0x800) { + length = 0x800; + } else { + length = *count - done; + } + + error = TRKGetFreeBuffer(&bufferId, &buffer); + + if (error == DS_NoError) + error = TRKAppendBuffer1_ui8(buffer, read ? DSMSG_ReadFile + : DSMSG_WriteFile); + + if (error == DS_NoError) + error = TRKAppendBuffer1_ui32(buffer, file_handle); + + if (error == DS_NoError) + error = TRKAppendBuffer1_ui16(buffer, length); + + if (!read && error == DS_NoError) + error = TRKAppendBuffer_ui8(buffer, data + done, length); + + if (error == DS_NoError) { + if (need_reply) { + replyLength = 0; + replyIOResult = 0; + + error = TRKRequestSend(buffer, &replyBufferId, read ? 5 : 5, 3, + !(read && file_handle == 0)); + if (error == DS_NoError) { + replyBuffer = (TRKBuffer*)TRKGetBuffer(replyBufferId); + TRKSetBufferPosition(replyBuffer, 2); + } + + if (error == DS_NoError) + error = TRKReadBuffer1_ui8(replyBuffer, &replyIOResult); + + if (error == DS_NoError) + error = TRKReadBuffer1_ui16(replyBuffer, &replyLength); + + if (read && error == DS_NoError) { + if (replyBuffer->length != replyLength + 5) { + replyLength = replyBuffer->length - 5; + if (replyIOResult == 0) + replyIOResult = 1; + } + + if (replyLength <= length) + error = TRKReadBuffer_ui8(replyBuffer, data + done, + replyLength); + } + + if (replyLength != length) { + if ((!read || replyLength >= length) && replyIOResult == 0) + replyIOResult = 1; + length = replyLength; + exit = TRUE; + } + + *io_result = (DSIOResult)replyIOResult; + TRKReleaseBuffer(replyBufferId); + } else { + error = TRKMessageSend((TRK_Msg*)buffer); + } + } + + TRKReleaseBuffer(bufferId); + done += length; + } + + *count = done; + return error; +} + +DSError TRKRequestSend(TRKBuffer* msgBuf, int* bufferId, u32 p1, u32 p2, int p3) +{ + int error = DS_NoError; + TRKBuffer* buffer; + u32 timer; + int tries; + u8 msg_command; + u8 msg_error; + BOOL badReply = TRUE; + + *bufferId = -1; + + for (tries = p2 + 1; tries != 0 && *bufferId == -1 && error == DS_NoError; + tries--) { + error = TRKMessageSend((TRK_Msg*)msgBuf); + if (error == DS_NoError) { + if (p3) { + timer = 0; + } + + while (TRUE) { + do { + *bufferId = TRKTestForPacket(); + if (*bufferId != -1) + break; + } while (!p3 || ++timer < 79999980); + + if (*bufferId == -1) + break; + + badReply = FALSE; + + buffer = TRKGetBuffer(*bufferId); + TRKSetBufferPosition(buffer, 0); + + if ((error = TRKReadBuffer1_ui8(buffer, &msg_command)) + != DS_NoError) + break; + + if (msg_command >= DSMSG_ReplyACK) + break; + + TRKProcessInput(*bufferId); + *bufferId = -1; + } + + if (*bufferId != -1) { + if (buffer->length < p1) { + badReply = TRUE; + } + if (error == DS_NoError && !badReply) { + error = TRKReadBuffer1_ui8(buffer, &msg_error); + } + if (error == DS_NoError && !badReply) { + if (msg_command != DSMSG_ReplyACK + || msg_error != DSREPLY_NoError) { + badReply = TRUE; + } + } + if (error != DS_NoError || badReply) { + TRKReleaseBuffer(*bufferId); + *bufferId = -1; + } + } + } + } + + if (*bufferId == -1) { + error = DS_Error800; + } + + return error; +} diff --git a/src/TRK_MINNOW_DOLPHIN/targcont.c b/src/TRK_MINNOW_DOLPHIN/targcont.c new file mode 100644 index 00000000..1827ae1a --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/targcont.c @@ -0,0 +1,12 @@ +#include "TRK_MINNOW_DOLPHIN/Os/dolphin/targcont.h" +#include "TRK_MINNOW_DOLPHIN/Os/dolphin/dolphin_trk_glue.h" +#include "TRK_MINNOW_DOLPHIN/ppc/Generic/targimpl.h" + +DSError TRKTargetContinue(void) +{ + TRKTargetSetStopped(0); + UnreserveEXI2Port(); + TRKSwapAndGo(); + ReserveEXI2Port(); + return 0; +} diff --git a/src/TRK_MINNOW_DOLPHIN/targimpl.c b/src/TRK_MINNOW_DOLPHIN/targimpl.c new file mode 100644 index 00000000..858024a5 --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/targimpl.c @@ -0,0 +1,1177 @@ +#include "TRK_MINNOW_DOLPHIN/ppc/Generic/targimpl.h" +#include "TRK_MINNOW_DOLPHIN/Os/dolphin/dolphin_trk.h" +#include "TRK_MINNOW_DOLPHIN/ppc/Generic/flush_cache.h" +#include "TRK_MINNOW_DOLPHIN/ppc/Generic/mpc_7xx_603e.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msgbuf.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/support.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/notify.h" +#include "stddef.h" +#include "string.h" + +typedef struct memRange { + u8* start; + u8* end; + BOOL readable; + BOOL writeable; +} memRange; + +const memRange gTRKMemMap[1] = { { (u8*)0, (u8*)-1, TRUE, TRUE } }; + +typedef struct StopInfo_PPC { + u32 PC; + u32 PCInstruction; + u16 exceptionID; +} StopInfo_PPC; + +typedef struct TRKExceptionStatus { + StopInfo_PPC exceptionInfo; + u8 inTRK; + u8 exceptionDetected; +} TRKExceptionStatus; + +typedef struct TRKStepStatus { + BOOL active; // 0x0 + DSMessageStepOptions type; // 0x4 + u32 count; // 0x8 + u32 rangeStart; // 0xC + u32 rangeEnd; // 0x10 +} TRKStepStatus; + +ProcessorRestoreFlags_PPC gTRKRestoreFlags = { FALSE, FALSE }; + +static TRKExceptionStatus gTRKExceptionStatus = { { 0, 0, 0 }, TRUE, 0 }; + +static TRKStepStatus gTRKStepStatus = { FALSE, DSSTEP_IntoCount, 0, 0 }; + +static u16 TRK_saved_exceptionID = 0; +ProcessorState_PPC gTRKCPUState; +TRKState gTRKState; + +typedef unsigned char u128[16]; +u128 TRKvalue128_temp; + +Default_PPC gTRKSaveState; + +// Instruction macros +#define INSTR_NOP 0x60000000 +#define INSTR_BLR 0x4E800020 +#define INSTR_PSQ_ST(psr, offset, rDest, w, gqr) \ + (0xF0000000 | (psr << 21) | (rDest << 16) | (w << 15) | (gqr << 12) \ + | offset) +#define INSTR_PSQ_L(psr, offset, rSrc, w, gqr) \ + (0xE0000000 | (psr << 21) | (rSrc << 16) | (w << 15) | (gqr << 12) | offset) +#define INSTR_STW(rSrc, offset, rDest) \ + (0x90000000 | (rSrc << 21) | (rDest << 16) | offset) +#define INSTR_LWZ(rDest, offset, rSrc) \ + (0x80000000 | (rDest << 21) | (rSrc << 16) | offset) +#define INSTR_STFD(fprSrc, offset, rDest) \ + (0xD8000000 | (fprSrc << 21) | (rDest << 16) | offset) +#define INSTR_LFD(fprDest, offset, rSrc) \ + (0xC8000000 | (fprDest << 21) | (rSrc << 16) | offset) +#define INSTR_MFSPR(rDest, spr) \ + (0x7C000000 | (rDest << 21) | ((spr & 0xFE0) << 6) | ((spr & 0x1F) << 16) \ + | 0x2A6) +#define INSTR_MTSPR(spr, rSrc) \ + (0x7C000000 | (rSrc << 21) | ((spr & 0xFE0) << 6) | ((spr & 0x1F) << 16) \ + | 0x3A6) + +#define DSFetch_u32(_p_) (*((u32*)_p_)) +#define DSFetch_u64(_p_) (*((u64*)_p_)) + +DSError TRKPPCAccessSPR(void* value, u32 spr_register_num, BOOL read); +DSError TRKPPCAccessPairedSingleRegister(void* srcDestPtr, u32 psr, BOOL read); +DSError TRKPPCAccessFPRegister(void* srcDestPtr, u32 fpr, BOOL read); +DSError TRKPPCAccessSpecialReg(void* value, u32* access_func, BOOL read); +static void TRKExceptionHandler(u16); +void TRKInterruptHandlerEnableInterrupts(void); +void WriteFPSCR(register f64*); +void ReadFPSCR(register f64*); +void __TRK_set_MSR(u32 msr); +u32 __TRK_get_MSR(); +static void TRK_ppc_memcpy(register void* dest, register const void* src, + register int n, register u32 param_4, + register u32 param_5); + +void TRKRestoreExtended1Block(); +void TRKUARTInterruptHandler(); + +static BOOL TRKTargetCheckStep(); + +asm u32 __TRK_get_MSR() +{ +#ifdef __MWERKS__ // clang-format off + nofralloc + mfmsr r3 + blr +#endif // clang-format on +} + +asm void __TRK_set_MSR(register u32 msr) { +#ifdef __MWERKS__ // clang-format off + nofralloc + mtmsr msr + blr +#endif // clang-format on +} + +DSError TRKValidMemory32(const void* addr, size_t length, + ValidMemoryOptions readWriteable) +{ + DSError err = DS_InvalidMemory; /* assume range is invalid */ + + const u8* start; + const u8* end; + + s32 i; + + /* + ** Get start and end addresses for the memory range and + ** verify that they are reasonable. + */ + + start = (const u8*)addr; + end = ((const u8*)addr + (length - 1)); + + if (end < start) + return DS_InvalidMemory; + + /* + ** Iterate through the gTRKMemMap array to determine if the requested + ** range falls within the valid ranges in the map. + */ + + for (i = 0; (i < (s32)(sizeof(gTRKMemMap) / sizeof(memRange))); i++) { + /* + ** If the requested range is not completely above + ** the valid range AND it is not completely below + ** the valid range then it must overlap somewhere. + ** If the requested range overlaps with one of the + ** valid ranges, do some additional checking. + ** + */ + + if ((start <= (const u8*)gTRKMemMap[i].end) + && (end >= (const u8*)gTRKMemMap[i].start)) { + /* + ** First, verify that the read/write attributes are + ** acceptable. If so, then recursively check any + ** part of the requested range that falls before or + ** after the valid range. + */ + + if (((readWriteable == VALIDMEM_Readable) + && !gTRKMemMap[i].readable) + || ((readWriteable == VALIDMEM_Writeable) + && !gTRKMemMap[i].writeable)) { + err = DS_InvalidMemory; + } else { + err = DS_NoError; + + /* + ** If a portion of the requested range falls before + ** the current valid range, then recursively + ** check it. + */ + + if (start < (const u8*)gTRKMemMap[i].start) + err = TRKValidMemory32( + start, (u32)((const u8*)gTRKMemMap[i].start - start), + readWriteable); + + /* + ** If a portion of the requested range falls after + ** the current valid range, then recursively + ** check it. + ** Note: Only do this step if the previous check + ** did not detect invalid access. + */ + + if ((err == DS_NoError) && (end > (const u8*)gTRKMemMap[i].end)) + err = TRKValidMemory32( + (const u8*)gTRKMemMap[i].end, + (u32)(end - (const u8*)gTRKMemMap[i].end), + readWriteable); + } + + break; + } + } + + return err; +} + +static asm void TRK_ppc_memcpy(register void* dest, register const void* src, + register int n, register u32 param_4, + register u32 param_5) { +#ifdef __MWERKS__ // clang-format off +#define msr r8 +#define byte r9 +#define count r10 + nofralloc + + mfmsr msr + li count, 0 + +top_loop: + cmpw count, n + beq out_loop + + mtmsr param_5 + sync + + lbzx byte, count, src + + mtmsr param_4 + sync + + stbx byte, count, dest + + addi count, count, 1 + + b top_loop +out_loop: + mtmsr msr + sync + + blr +#undef count +#undef byte +#undef msr +#endif // clang-format on +} + +DSError TRKTargetAccessMemory(void* data, u32 start, size_t* length, + MemoryAccessOptions accessOptions, BOOL read) +{ + DSError error; + u32 target_msr; + void* addr; + u32 trk_msr; + TRKExceptionStatus tempExceptionStatus = gTRKExceptionStatus; + gTRKExceptionStatus.exceptionDetected = FALSE; + + addr = (void*)TRKTargetTranslate(start); + error = TRKValidMemory32(addr, *length, + read ? VALIDMEM_Readable : VALIDMEM_Writeable); + + if (error != DS_NoError) { + *length = 0; + } else { + target_msr = __TRK_get_MSR(); + trk_msr = target_msr | gTRKCPUState.Extended1.MSR & 0x10; + + if (read) { + TRK_ppc_memcpy(data, addr, *length, target_msr, trk_msr); + } else { + TRK_ppc_memcpy(addr, data, *length, trk_msr, target_msr); + TRK_flush_cache(addr, *length); + if ((void*)start != addr) { + TRK_flush_cache((void*)start, *length); + } + } + } + + if (gTRKExceptionStatus.exceptionDetected) { + *length = 0; + error = DS_CWDSException; + } + + gTRKExceptionStatus = tempExceptionStatus; + return error; +} + +DSError TRKTargetReadInstruction(void* data, u32 start) +{ + DSError error; + size_t registersLength = 4; + + error = TRKTargetAccessMemory(data, start, ®istersLength, + MEMACCESS_UserMemory, TRUE); + + if (error == DS_NoError && registersLength != 4) { + error = DS_InvalidMemory; + } + + return error; +} + +DSError TRKTargetAccessDefault(u32 firstRegister, u32 lastRegister, + TRKBuffer* b, size_t* registersLengthPtr, + BOOL read) +{ + DSError error; + u32 count; + u32* data; + TRKExceptionStatus tempExceptionStatus; + + if (lastRegister > 0x24) { + return DS_InvalidRegister; + } + + tempExceptionStatus = gTRKExceptionStatus; + + data = gTRKCPUState.Default.GPR + firstRegister; + + count = (lastRegister - firstRegister) + 1; + + gTRKExceptionStatus.exceptionDetected = FALSE; + + *registersLengthPtr = count * sizeof(u32); + + if (read) { + error = TRKAppendBuffer_ui32(b, data, count); + } else { + error = TRKReadBuffer_ui32(b, data, count); + } + + if (gTRKExceptionStatus.exceptionDetected) { + *registersLengthPtr = 0; + error = DS_CWDSException; + } + + gTRKExceptionStatus = tempExceptionStatus; + return error; +} + +DSError TRKTargetAccessFP(u32 firstRegister, u32 lastRegister, TRKBuffer* b, + size_t* registersLengthPtr, BOOL read) +{ + u64 temp; + DSError error; + TRKExceptionStatus tempExceptionStatus; + u32 current; + + if (lastRegister > 0x21) { + return DS_InvalidRegister; + } + + tempExceptionStatus = gTRKExceptionStatus; + gTRKExceptionStatus.exceptionDetected = FALSE; + + __TRK_set_MSR(__TRK_get_MSR() | 0x2000); + + *registersLengthPtr = 0; + error = DS_NoError; + + for (current = firstRegister; + (current <= lastRegister) && (error == DS_NoError); + current++, *registersLengthPtr += sizeof(f64)) { + if (read) { + TRKPPCAccessFPRegister(&temp, current, read); + error = TRKAppendBuffer1_ui64(b, temp); + } else { + TRKReadBuffer1_ui64(b, &temp); + error = TRKPPCAccessFPRegister(&temp, current, read); + } + } + + if (gTRKExceptionStatus.exceptionDetected) { + *registersLengthPtr = 0; + error = DS_CWDSException; + } + + gTRKExceptionStatus = tempExceptionStatus; + return error; +} + +DSError TRKTargetAccessExtended1(u32 firstRegister, u32 lastRegister, + TRKBuffer* b, size_t* registersLengthPtr, + BOOL read) +{ + TRKExceptionStatus tempExceptionStatus; + int error; + u32* data; + int count; + + if (lastRegister > 0x60) { + return DS_InvalidRegister; + } + + tempExceptionStatus = gTRKExceptionStatus; + gTRKExceptionStatus.exceptionDetected = FALSE; + + *registersLengthPtr = 0; + + if (firstRegister <= lastRegister) { + data = (u32*)&gTRKCPUState.Extended1 + firstRegister; + count = lastRegister - firstRegister + 1; + *registersLengthPtr += count * sizeof(u32); + + if (read) { + error = TRKAppendBuffer_ui32(b, data, count); + } else { + if (data <= &gTRKCPUState.Extended1.TBU + && (data + count - 1) >= &gTRKCPUState.Extended1.TBL) { + gTRKRestoreFlags.TBR = 1; + } + + if (data <= &gTRKCPUState.Extended1.DEC + && (data + count - 1) >= &gTRKCPUState.Extended1.DEC) { + gTRKRestoreFlags.DEC = 1; + } + error = TRKReadBuffer_ui32(b, data, count); + } + } + if (gTRKExceptionStatus.exceptionDetected) { + *registersLengthPtr = 0; + error = DS_CWDSException; + } + + gTRKExceptionStatus = tempExceptionStatus; + return error; +} + +DSError TRKTargetAccessExtended2(u32 firstRegister, u32 lastRegister, + TRKBuffer* b, size_t* registerStorageSize, + BOOL read) +{ + TRKExceptionStatus savedException; + u32 i; + u32 value_buf0[1]; + u32 value_buf[2]; + DSError err; + u32 access_func[10]; + + if (lastRegister > 0x1f) + return DS_InvalidRegister; + + /* + ** Save any existing exception status and clear the exception flag. + ** This allows detection of exceptions that occur ONLY within this + ** function. + */ + + savedException = gTRKExceptionStatus; + gTRKExceptionStatus.exceptionDetected = FALSE; + + TRKPPCAccessSPR(value_buf0, SPR_HID2, TRUE); + + value_buf0[0] |= 0xA0000000; + TRKPPCAccessSPR(value_buf0, SPR_HID2, FALSE); + + value_buf0[0] = 0; + TRKPPCAccessSPR(value_buf0, SPR_GQR0, FALSE); + + *registerStorageSize = 0; + err = DS_NoError; + + for (i = firstRegister; (i <= lastRegister) && (err == DS_NoError); i++) { + if (read) { + err = TRKPPCAccessPairedSingleRegister((u64*)value_buf, i, read); + err = TRKAppendBuffer1_ui64(b, *(u64*)value_buf); + } else { + err = TRKReadBuffer1_ui64(b, (u64*)value_buf); + err = TRKPPCAccessPairedSingleRegister((u64*)value_buf, i, read); + } + + *registerStorageSize += sizeof(u64); + } + + if (gTRKExceptionStatus.exceptionDetected) { + *registerStorageSize = 0; + err = DS_CWDSException; + } + + gTRKExceptionStatus = savedException; + + return err; +} + +DSError TRKTargetVersions(DSVersions* versions) +{ + versions->kernelMajor = 0; + versions->kernelMinor = 8; + versions->protocolMajor = 1; + versions->protocolMinor = 10; + return DS_NoError; +} + +DSError TRKTargetSupportMask(u8 mask[32]) +{ + mask[0] = 0x7a; + mask[1] = 0; + mask[2] = 0x4f; + mask[3] = 7; + mask[4] = 0; + mask[5] = 0; + mask[6] = 0; + mask[7] = 0; + mask[8] = 0; + mask[9] = 0; + mask[10] = 0; + mask[0xb] = 0; + mask[0xc] = 0; + mask[0xd] = 0; + mask[0xe] = 0; + mask[0xf] = 0; + mask[0x10] = 1; + mask[0x11] = 0; + mask[0x12] = 3; + mask[0x13] = 0; + mask[0x14] = 0; + mask[0x15] = 0; + mask[0x16] = 0; + mask[0x17] = 0; + mask[0x18] = 0; + mask[0x19] = 0; + mask[0x1a] = 3; + mask[0x1b] = 0; + mask[0x1c] = 0; + mask[0x1d] = 0; + mask[0x1e] = 0; + mask[0x1f] = 0x80; + return DS_NoError; +} + +extern BOOL gTRKBigEndian; + +DSError TRKTargetCPUType(DSCPUType* cpuType) +{ + cpuType->cpuMajor = 0; + cpuType->cpuMinor = TRKTargetCPUMinorType(); + cpuType->bigEndian = gTRKBigEndian; + cpuType->defaultTypeSize = 4; + cpuType->fpTypeSize = 8; + cpuType->extended1TypeSize = 4; + cpuType->extended2TypeSize = 8; + return DS_NoError; +} + +asm void TRKInterruptHandler() +{ +#ifdef __MWERKS__ // clang-format off + nofralloc + mtsrr0 r2 + mtsrr1 r4 + mfsprg r4, 3 + mfcr r2 + mtsprg 3, r2 + lis r2, gTRKState@h + ori r2, r2, gTRKState@l + lwz r2, TRKState_PPC.MSR(r2) + ori r2, r2, 0x8002 + xori r2, r2, 0x8002 + sync + mtmsr r2 + sync + lis r2, TRK_saved_exceptionID@h + ori r2, r2, TRK_saved_exceptionID@l + sth r3, 0(r2) + cmpwi r3, 0x500 + bne L_802CF694 + lis r2, gTRKCPUState@h + ori r2, r2, gTRKCPUState@l + mflr r3 + stw r3, ProcessorState_PPC.transport_handler_saved_ra(r2) + bl TRKUARTInterruptHandler + lis r2, gTRKCPUState@h + ori r2, r2, gTRKCPUState@l + lwz r3, ProcessorState_PPC.transport_handler_saved_ra(r2) + mtlr r3 + lis r2, gTRKState@h + ori r2, r2, gTRKState@l + lwz r2, TRKState_PPC.inputPendingPtr(r2) + lbz r2, TRKState_PPC.GPR[0](r2) + cmpwi r2, 0 + beq L_802CF678 + lis r2, gTRKExceptionStatus@h + ori r2, r2, gTRKExceptionStatus@l + lbz r2, TRKExceptionStatus.inTRK(r2) + cmpwi r2, 1 + beq L_802CF678 + lis r2, gTRKState@h + ori r2, r2, gTRKState@l + li r3, 1 + stb r3, TRKState_PPC.inputActivated(r2) + b L_802CF694 +L_802CF678: + lis r2, gTRKSaveState@h + ori r2, r2, gTRKSaveState@l + lwz r3, Default_PPC.CR(r2) + mtcrf 0xff, r3 + lwz r3, Default_PPC.GPR[3](r2) + lwz r2, Default_PPC.GPR[2](r2) + rfi +L_802CF694: + lis r2, TRK_saved_exceptionID@h + ori r2, r2, TRK_saved_exceptionID@l + lhz r3, 0(r2) + lis r2, gTRKExceptionStatus@h + ori r2, r2, gTRKExceptionStatus@l + lbz r2, TRKExceptionStatus.inTRK(r2) + cmpwi r2, 0 + bne TRKExceptionHandler + lis r2, gTRKCPUState@h + ori r2, r2, gTRKCPUState@l + stw r0, ProcessorState_PPC.Default.GPR[0](r2) + stw r1, ProcessorState_PPC.Default.GPR[1](r2) + mfsprg r0, 1 + stw r0, ProcessorState_PPC.Default.GPR[2](r2) + sth r3, ProcessorState_PPC.Extended1.exceptionID(r2) + sth r3, (ProcessorState_PPC.Extended1.exceptionID + 2)(r2) + mfsprg r0, 2 + stw r0, ProcessorState_PPC.Default.GPR[3](r2) + stmw r4, ProcessorState_PPC.Default.GPR[4](r2) + mfsrr0 r27 + mflr r28 + mfsprg r29, 3 + mfctr r30 + mfxer r31 + stmw r27, ProcessorState_PPC.Default.PC(r2) + bl TRKSaveExtended1Block + lis r2, gTRKExceptionStatus@h + ori r2, r2, gTRKExceptionStatus@l + li r3, 1 + stb r3, TRKExceptionStatus.inTRK(r2) + lis r2, gTRKState@h + ori r2, r2, gTRKState@l + lwz r0, TRKState_PPC.MSR(r2) + sync + mtmsr r0 + sync + lwz r0, TRKState_PPC.LR(r2) + mtlr r0 + lwz r0, TRKState_PPC.CTR(r2) + mtctr r0 + lwz r0, TRKState_PPC.XER(r2) + mtxer r0 + lwz r0, TRKState_PPC.DSISR(r2) + mtdsisr r0 + lwz r0, TRKState_PPC.DAR(r2) + mtdar r0 + lmw r3, TRKState_PPC.GPR[3](r2) + lwz r0, TRKState_PPC.GPR[0](r2) + lwz r1, TRKState_PPC.GPR[1](r2) + lwz r2, TRKState_PPC.GPR[2](r2) + b TRKPostInterruptEvent +#endif // clang-format on +} + +static asm void TRKExceptionHandler(u16) +{ +#ifdef __MWERKS__ // clang-format off + nofralloc + lis r2, gTRKExceptionStatus@h + ori r2, r2, gTRKExceptionStatus@l + sth r3, TRKExceptionStatus.exceptionInfo.exceptionID(r2) + mfsrr0 r3 + stw r3, TRKExceptionStatus.exceptionInfo.PC(r2) + lhz r3, TRKExceptionStatus.exceptionInfo.exceptionID(r2) + cmpwi r3, 0x200 + beq LAB_00010ba4 + cmpwi r3, 0x300 + beq LAB_00010ba4 + cmpwi r3, 0x400 + beq LAB_00010ba4 + cmpwi r3, 0x600 + beq LAB_00010ba4 + cmpwi r3, 0x700 + beq LAB_00010ba4 + cmpwi r3, 0x800 + beq LAB_00010ba4 + cmpwi r3, 0x1000 + beq LAB_00010ba4 + cmpwi r3, 0x1100 + beq LAB_00010ba4 + cmpwi r3, 0x1200 + beq LAB_00010ba4 + cmpwi r3, 0x1300 + beq LAB_00010ba4 + b LAB_00010bb0 +LAB_00010ba4: + mfsrr0 r3 + addi r3, r3, 0x4 + mtsrr0 r3 +LAB_00010bb0: + lis r2, gTRKExceptionStatus@h + ori r2, r2, gTRKExceptionStatus@l + li r3, 0x1 + stb r3, TRKExceptionStatus.exceptionDetected(r2) + mfsprg r3, 3 + mtcrf 0xff, r3 + mfsprg r2, 1 + mfsprg r3, 2 + rfi +#endif // clang-format on +} + +void TRKPostInterruptEvent(void) +{ + NubEventType eventType; + u32 inst; + TRKEvent event; + + if (gTRKState.inputActivated) { + gTRKState.inputActivated = FALSE; + } else { + switch (gTRKCPUState.Extended1.exceptionID & 0xFFFF) { + case 0xd00: + case 0x700: + TRKTargetReadInstruction(&inst, gTRKCPUState.Default.PC); + + if (inst == 0xfe00000) { + eventType = NUBEVENT_Support; + } else { + eventType = NUBEVENT_Breakpoint; + } + break; + default: + eventType = NUBEVENT_Exception; + break; + } + + TRKConstructEvent(&event, eventType); + TRKPostEvent(&event); + } +} + +asm void TRKSwapAndGo() +{ +#ifdef __MWERKS__ // clang-format off + nofralloc + lis r3, gTRKState@h + ori r3, r3, gTRKState@l + stmw r0, TRKState_PPC.GPR[0](r3) + mfmsr r0 + stw r0, TRKState_PPC.MSR(r3) + mflr r0 + stw r0, TRKState_PPC.LR(r3) + mfctr r0 + stw r0, TRKState_PPC.CTR(r3) + mfxer r0 + stw r0, TRKState_PPC.XER(r3) + mfdsisr r0 + stw r0, TRKState_PPC.DSISR(r3) + mfdar r0 + stw r0, TRKState_PPC.DAR(r3) + li r1, -0x7ffe + nor r1, r1, r1 + mfmsr r3 + and r3, r3, r1 + mtmsr r3 + lis r2, gTRKState@h + ori r2, r2, gTRKState@l + lwz r2, TRKState_PPC.inputPendingPtr(r2) + lbz r2, TRKState_PPC.GPR[0](r2) + cmpwi r2, 0 + beq L_802CF930 + lis r2, gTRKState@h + ori r2, r2, gTRKState@l + li r3, 1 + stb r3, TRKState_PPC.inputActivated(r2) + b TRKInterruptHandlerEnableInterrupts +L_802CF930: + lis r2, gTRKExceptionStatus@h + ori r2, r2, gTRKExceptionStatus@l + li r3, 0 + stb r3, 0xc(r2) + bl TRKRestoreExtended1Block + lis r2, gTRKCPUState@h + ori r2, r2, gTRKCPUState@l + lmw r27, ProcessorState_PPC.Default.PC(r2) + mtsrr0 r27 + mtlr r28 + mtcrf 0xff, r29 + mtctr r30 + mtxer r31 + lmw r3, ProcessorState_PPC.Default.GPR[3](r2) + lwz r0, ProcessorState_PPC.Default.GPR[0](r2) + lwz r1, ProcessorState_PPC.Default.GPR[1](r2) + lwz r2, ProcessorState_PPC.Default.GPR[2](r2) + rfi +#endif // clang-format on +} + +asm void TRKInterruptHandlerEnableInterrupts(void) +{ +#ifdef __MWERKS__ // clang-format off + nofralloc; + lis r2, gTRKState@h + ori r2, r2, gTRKState@l + lwz r0, TRKState_PPC.MSR(r2) + sync + mtmsr r0 + sync + lwz r0, TRKState_PPC.LR(r2) + mtlr r0 + lwz r0, TRKState_PPC.CTR(r2) + mtctr r0 + lwz r0, TRKState_PPC.XER(r2) + mtxer r0 + lwz r0, TRKState_PPC.DSISR(r2) + mtdsisr r0 + lwz r0, TRKState_PPC.DAR(r2) + mtdar r0 + lmw r3, TRKState_PPC.GPR[3](r2) + lwz r0, TRKState_PPC.GPR[0](r2) + lwz r1, TRKState_PPC.GPR[1](r2) + lwz r2, TRKState_PPC.GPR[2](r2) + b TRKPostInterruptEvent +#endif // clang-format on +} + +DSError TRKTargetInterrupt(TRKEvent* event) +{ + DSError error = DS_NoError; + switch (event->eventType) { + case NUBEVENT_Breakpoint: + case NUBEVENT_Exception: + if (TRKTargetCheckStep() == FALSE) { + TRKTargetSetStopped(TRUE); + error = TRKDoNotifyStopped(DSMSG_NotifyStopped); + } + break; + default: + break; + } + + return error; +} + +DSError TRKTargetAddStopInfo(TRKBuffer* buffer) +{ + DSError error; + u32 instruction; + + error = TRKAppendBuffer1_ui32(buffer, gTRKCPUState.Default.PC); + if (error == 0) { + error = TRKTargetReadInstruction(&instruction, gTRKCPUState.Default.PC); + } + if (error == 0) + error = TRKAppendBuffer1_ui32(buffer, instruction); + if (error == 0) + error + = TRKAppendBuffer1_ui16(buffer, gTRKCPUState.Extended1.exceptionID); + return error; +} + +DSError TRKTargetAddExceptionInfo(TRKBuffer* buffer) +{ + DSError error; + u32 local_10; + + error = TRKAppendBuffer1_ui32(buffer, gTRKExceptionStatus.exceptionInfo.PC); + if (error == 0) { + error = TRKTargetReadInstruction(&local_10, + gTRKExceptionStatus.exceptionInfo.PC); + } + if (error == 0) { + error = TRKAppendBuffer1_ui32(buffer, local_10); + } + if (error == 0) { + error = TRKAppendBuffer1_ui16( + buffer, gTRKExceptionStatus.exceptionInfo.exceptionID); + } + + return error; +} + +static DSError TRKTargetEnableTrace(BOOL val) +{ + if (val) { + gTRKCPUState.Extended1.MSR = (gTRKCPUState.Extended1.MSR | 0x400); + } else { + gTRKCPUState.Extended1.MSR = (gTRKCPUState.Extended1.MSR & ~0x400); + } + return DS_NoError; +} + +static BOOL TRKTargetStepDone() +{ + BOOL result = TRUE; + + if (gTRKStepStatus.active + && ((u16)gTRKCPUState.Extended1.exceptionID) == PPC_Trace) { + switch (gTRKStepStatus.type) { + case DSSTEP_IntoCount: + if (gTRKStepStatus.count > 0) { + result = FALSE; + } + break; + case DSSTEP_IntoRange: + if (gTRKCPUState.Default.PC >= gTRKStepStatus.rangeStart + && gTRKCPUState.Default.PC <= gTRKStepStatus.rangeEnd) { + result = FALSE; + } + break; + default: + break; + } + } + + return result; +} + +static DSError TRKTargetDoStep() +{ + gTRKStepStatus.active = TRUE; + TRKTargetEnableTrace(TRUE); + + if (gTRKStepStatus.type == DSSTEP_IntoCount + || gTRKStepStatus.type == DSSTEP_OverCount) { + gTRKStepStatus.count--; + } + + TRKTargetSetStopped(FALSE); + return DS_NoError; +} + +static BOOL TRKTargetCheckStep() +{ + if (gTRKStepStatus.active) { + TRKTargetEnableTrace(FALSE); + + if (TRKTargetStepDone()) { + gTRKStepStatus.active = FALSE; + } else { + TRKTargetDoStep(); + } + } + + return gTRKStepStatus.active; +} + +DSError TRKTargetSingleStep(u32 count, BOOL stepOver) +{ + DSError error = DS_NoError; + + if (stepOver) { + error = DS_UnsupportedError; + } else { + gTRKStepStatus.count = count; + gTRKStepStatus.type = DSSTEP_IntoCount; + error = TRKTargetDoStep(); + } + + return error; +} + +DSError TRKTargetStepOutOfRange(u32 rangeStart, u32 rangeEnd, BOOL stepOver) +{ + DSError error = DS_NoError; + + if (stepOver) { + // Stepping over isn't supported for PowerPC + error = DS_UnsupportedError; + } else { + gTRKStepStatus.type = DSSTEP_IntoRange; + // gTRKStepStatus.active = TRUE; + gTRKStepStatus.rangeStart = rangeStart; + gTRKStepStatus.rangeEnd = rangeEnd; + error = TRKTargetDoStep(); + } + + return error; +} + +u32 TRKTargetGetPC() { return gTRKCPUState.Default.PC; } + +DSError TRKTargetSupportRequest() +{ + DSError error; + size_t* length; + DSIOResult ioResult; + MessageCommandID commandId; + TRKEvent event; + + commandId = gTRKCPUState.Default.GPR[3]; + if (commandId != DSMSG_ReadFile && commandId != DSMSG_WriteFile) { + TRKConstructEvent(&event, 4); + TRKPostEvent(&event); + return DS_NoError; + } else { + length = (size_t*)gTRKCPUState.Default.GPR[5]; + error = TRKSuppAccessFile((u8)gTRKCPUState.Default.GPR[4], + (u8*)gTRKCPUState.Default.GPR[6], length, + &ioResult, TRUE, commandId == DSMSG_ReadFile); + + if (ioResult == DS_IONoError && error != DS_NoError) { + ioResult = DS_IOError; + } + + gTRKCPUState.Default.GPR[3] = ioResult; + + if (commandId == DSMSG_ReadFile) { + TRK_flush_cache((void*)gTRKCPUState.Default.GPR[6], *length); + } + } + + gTRKCPUState.Default.PC += 4; + return error; +} + +DSError TRKTargetFlushCache(u8, void* start, void* end) +{ + if (start < end) { + TRK_flush_cache(start, (u8*)end - (u8*)start); + return DS_NoError; + } + + return DS_InvalidMemory; +} + +BOOL TRKTargetStopped() { return gTRKState.isStopped; } + +void TRKTargetSetStopped(unsigned int stopped) +{ + gTRKState.isStopped = stopped; +} + +u32 TRKTargetStop() +{ + TRKTargetSetStopped(1); + return 0; +} + +DSError TRKPPCAccessSPR(void* value, u32 spr_register_num, BOOL read) +{ + /* Initialize instruction array with nop */ + + u32 access_func[5] + = { INSTR_NOP, INSTR_NOP, INSTR_NOP, INSTR_NOP, INSTR_NOP }; + /* + ** Construct a small assembly function to perform the + ** requested access and call it. The read/write function + ** is in the form: + ** + ** read: + ** mfspr r4, spr_register_num + ** stw r4, 0(r3) + ** blr + ** + ** write: + ** lwz r4, 0(r3) + ** mtspr spr_register_num, r4 + ** blr + ** + */ + + if (read) { + access_func[0] = INSTR_MFSPR(4, spr_register_num); + access_func[1] = (u32)INSTR_STW(4, 0, 3); + } else { + access_func[0] = (u32)INSTR_LWZ(4, 0, 3); + access_func[1] = INSTR_MTSPR(spr_register_num, 4); + } + + return TRKPPCAccessSpecialReg(value, access_func, read); +} + +DSError TRKPPCAccessPairedSingleRegister(void* srcDestPtr, u32 psr, BOOL read) +{ + // all nop by default + u32 instructionData[] + = { INSTR_NOP, INSTR_NOP, INSTR_NOP, INSTR_NOP, INSTR_NOP }; + + if (read) { + instructionData[0] + = INSTR_PSQ_ST(psr, 0, 3, 0, 0); // psq_st psr, 0(r3), 0, 0 + } else { + instructionData[0] + = INSTR_PSQ_L(psr, 0, 3, 0, 0); // psq_l psr, 0(r3), 0, 0 + } + + return TRKPPCAccessSpecialReg(srcDestPtr, instructionData, read); +} + +DSError TRKPPCAccessFPRegister(void* srcDestPtr, u32 fpr, BOOL read) +{ + DSError error = DS_NoError; + // all nop by default + u32 instructionData1[] + = { INSTR_NOP, INSTR_NOP, INSTR_NOP, INSTR_NOP, INSTR_NOP }; + + if (fpr < 0x20) { + if (read) { + instructionData1[0] = INSTR_STFD(fpr, 0, 3); // stfd fpr, 0(r3) + } else { + instructionData1[0] = INSTR_LFD(fpr, 0, 3); // lfd fpr, 0(r3) + } + + error = TRKPPCAccessSpecialReg(srcDestPtr, instructionData1, read); + } else if (fpr == 0x20) { + if (read) { + instructionData1[0] = INSTR_STFD(1, 0, 4); // stfd f1, 0(r4) + instructionData1[1] = 0xfc20048e; // mtfsf 0xff, f1 + instructionData1[2] = INSTR_STFD(1, 0, 3); // stfd f1, 0(r3) + instructionData1[3] = INSTR_LFD(1, 0, 4); // lfd f1, 0(r4) + } else { + instructionData1[0] = INSTR_STFD(1, 0, 4); // stfd f1, 0(r4) + instructionData1[1] = INSTR_LFD(1, 0, 3); // lfd f1, 0(r4) + instructionData1[2] = 0xfdfe0d8e; // mtfsf 0xff, f1 + instructionData1[3] = INSTR_LFD(1, 0, 4); // lfd f1, 0(r4) + } + error = TRKPPCAccessSpecialReg(srcDestPtr, instructionData1, read); + *(u64*)srcDestPtr &= 0xFFFFFFFF; + } else if (fpr == 0x21) { + if (!read) { + *(u32*)srcDestPtr = *((u32*)(srcDestPtr) + 1); + } + + error = TRKPPCAccessSPR(srcDestPtr, SPR_FPECR, read); + if (read) { + DSFetch_u64(srcDestPtr) = DSFetch_u32(srcDestPtr) & 0xffffffffLL; + } + } + + return error; +} + +#define DEBUG_VECTORREG_ACCESS 0 + +DSError TRKPPCAccessSpecialReg(void* value, u32* access_func, BOOL read) +{ + typedef void (*asm_access_type)(void*, void*); + + asm_access_type asm_access; + + /* + ** Construct a small assembly function to perform the + ** requested access and call it. The read/write function + ** is in the form: + ** + ** + ** blr + */ + + /* + ** Put blr instruction at the end of access function (it should be + ** a 5-instruction array w/the last one empty). + */ + + access_func[9] = INSTR_BLR; + + /* + ** Now that the instruction array is built, get a function pointer to it. + */ + + asm_access = (asm_access_type)access_func; + +#if DEBUG_VECTORREG_ACCESS + + __puts("\r\nasm_access: "); + __puthex8((u32)asm_access); + __puts(" access_func: "); + __puthex8((u32)access_func); + + for (i = 0; i < 10; i++) { + __puts("\r\ninst["); + __puthex2(i); + __puts("]: "); + __puthex8(access_func[i]); + __puts(" ; "); + __puthex8(*((u32*)asm_access + i)); + } + + __puts("\r\n"); + +#endif + + // Flush cache + TRK_flush_cache(access_func, (sizeof(access_func) * 10)); + (*asm_access)((u32*)value, (void*)&TRKvalue128_temp); + + return DS_NoError; +} + +void TRKTargetSetInputPendingPtr(void* ptr) { gTRKState.inputPendingPtr = ptr; } diff --git a/src/TRK_MINNOW_DOLPHIN/usr_put.c b/src/TRK_MINNOW_DOLPHIN/usr_put.c new file mode 100644 index 00000000..eda11e06 --- /dev/null +++ b/src/TRK_MINNOW_DOLPHIN/usr_put.c @@ -0,0 +1,5 @@ +#include "TRK_MINNOW_DOLPHIN/Os/dolphin/usr_put.h" +#include "TRK_MINNOW_DOLPHIN/MetroTRK/Portable/msghndlr.h" +#include "PowerPC_EABI_Support/MetroTRK/trk.h" + +void usr_put_initialize(void) { } diff --git a/src/dolphin/gx/GXFifo.c b/src/dolphin/gx/GXFifo.c index 963be184..583303a0 100644 --- a/src/dolphin/gx/GXFifo.c +++ b/src/dolphin/gx/GXFifo.c @@ -6,15 +6,15 @@ #include -static OSThread *__GXCurrentThread; +static struct __GXFifoObj* CPUFifo; +static struct __GXFifoObj* GPFifo; +static OSThread* __GXCurrentThread; static GXBool CPGPLinked; static BOOL GXOverflowSuspendInProgress; static GXBreakPtCallback BreakPointCB; static u32 __GXOverflowCount; -struct __GXFifoObj *CPUFifo; -struct __GXFifoObj *GPFifo; -void *__GXCurrentBP; +void* __GXCurrentBP; static void __GXFifoReadEnable(void); static void __GXFifoReadDisable(void); @@ -38,10 +38,10 @@ static void GXUnderflowHandler(s16 interrupt, OSContext *context) { ASSERTLINE(0x1A3, GXOverflowSuspendInProgress); - OSResumeThread(__GXCurrentThread); - GXOverflowSuspendInProgress = FALSE; - __GXWriteFifoIntReset(1U, 1U); - __GXWriteFifoIntEnable(1U, 0U); + OSResumeThread(__GXCurrentThread); + GXOverflowSuspendInProgress = FALSE; + __GXWriteFifoIntReset(1U, 1U); + __GXWriteFifoIntEnable(1U, 0U); } #define SOME_SET_REG_MACRO(reg, size, shift, val) \ @@ -51,17 +51,17 @@ static void GXUnderflowHandler(s16 interrupt, OSContext *context) static void GXBreakPointHandler(s16 interrupt, OSContext *context) { - OSContext exceptionContext; + OSContext exceptionContext; - SOME_SET_REG_MACRO(gx->cpEnable, 1, 5, 0); - GX_SET_CP_REG(1, gx->cpEnable); - if (BreakPointCB != NULL) { - OSClearContext(&exceptionContext); - OSSetCurrentContext(&exceptionContext); - BreakPointCB(); - OSClearContext(&exceptionContext); - OSSetCurrentContext(context); - } + gx->cpEnable = gx->cpEnable & 0xFFFFFFDF; + __cpReg[1] = gx->cpEnable; + if (BreakPointCB != NULL) { + OSClearContext(&exceptionContext); + OSSetCurrentContext(&exceptionContext); + BreakPointCB(); + OSClearContext(&exceptionContext); + OSSetCurrentContext(context); + } } static void GXCPInterruptHandler(s16 interrupt, OSContext *context) diff --git a/src/dolphin/gx/GXFrameBuf.c b/src/dolphin/gx/GXFrameBuf.c index 4c04abab..9c12a892 100644 --- a/src/dolphin/gx/GXFrameBuf.c +++ b/src/dolphin/gx/GXFrameBuf.c @@ -291,26 +291,25 @@ f32 GXGetYScaleFactor(u16 efbHeight, u16 xfbHeight) u32 GXSetDispCopyYScale(f32 vscale) { - u8 enable; - u32 iScale; - u32 ht; - u32 reg; + u32 scale; + GXBool check; + u32 height; + u32 reg; - CHECK_GXBEGIN(0x615, "GXSetDispCopyYScale"); + scale = (u32)(256.0f / vscale) & 0x1FF; + check = (scale != 0x100); - ASSERTMSGLINE(0x617, vscale >= 1.0f, "GXSetDispCopyYScale: Vertical scale must be >= 1.0"); + reg = 0; + SET_REG_FIELD(0, reg, 9, 0, scale); + SET_REG_FIELD(0, reg, 8, 24, 0x4E); + GX_WRITE_RAS_REG(reg); + gx->bpSentNot = GX_FALSE; - iScale = (u32)(256.0f / vscale) & 0x1FF; - enable = (iScale != 256); + SET_REG_FIELD(0, gx->cpDisp, 1, 10, check); - reg = 0; - SET_REG_FIELD(0x61E, reg, 9, 0, iScale); - SET_REG_FIELD(0x61E, reg, 8, 24, 0x4E); - GX_WRITE_RAS_REG(reg); - gx->bpSentNot = 0; - SET_REG_FIELD(0x623, gx->cpDisp, 1, 10, enable); - ht = GET_REG_FIELD(gx->cpDispSize, 10, 10) + 1; - return __GXGetNumXfbLines(ht, iScale); + height = (gx->cpDispSize >> 10 & 0x3FF) + 1; + + return __GXGetNumXfbLines(height, scale); } void GXSetCopyClear(GXColor clear_clr, u32 clear_z) diff --git a/src/dolphin/gx/GXInit.c b/src/dolphin/gx/GXInit.c index 82874fab..e6774ba7 100644 --- a/src/dolphin/gx/GXInit.c +++ b/src/dolphin/gx/GXInit.c @@ -65,150 +65,134 @@ static GXTlutRegion *__GXDefaultTlutRegionCallback(u32 idx) GXFifoObj FifoObj; -GXFifoObj *GXInit(void *base, u32 size) +GXFifoObj* GXInit(void* base, u32 size) { - u32 i; - u32 reg; - u32 freqBase; + u32 i; + u32 reg; + u32 freqBase; + char stack_padding[8]; - // OSRegisterVersion(__GXVersion); + gx->inDispList = FALSE; + gx->dlSaveContext = TRUE; - gx->inDispList = FALSE; - gx->dlSaveContext = TRUE; - // gx->abtWaitPECopy = 1; -#if DEBUG - __GXinBegin = FALSE; -#endif - gx->tcsManEnab = FALSE; - gx->tevTcEnab = FALSE; - - GXSetMisc(GX_MT_XF_FLUSH, 0); + gx->tcsManEnab = FALSE; + gx->tevTcEnab = 0; + GXSetMisc(GX_MT_XF_FLUSH, 0); + __piReg = OSPhysicalToUncached(0xC003000); + __cpReg = OSPhysicalToUncached(0xC000000); + __peReg = OSPhysicalToUncached(0xC001000); + __memReg = OSPhysicalToUncached(0xC004000); + __GXFifoInit(); + GXInitFifoBase(&FifoObj, base, size); + GXSetCPUFifo(&FifoObj); + GXSetGPFifo(&FifoObj); + __GXPEInit(); + EnableWriteGatherPipe(); - __piReg = OSPhysicalToUncached(0xC003000); - __cpReg = OSPhysicalToUncached(0xC000000); - __peReg = OSPhysicalToUncached(0xC001000); - __memReg = OSPhysicalToUncached(0xC004000); - // __GXFifoInit(); - // GXInitFifoBase(&FifoObj, base, size); - // GXSetCPUFifo(&FifoObj); - // GXSetGPFifo(&FifoObj); + gx->genMode = 0; + SET_REG_FIELD(0, gx->genMode, 8, 24, 0); + gx->bpMask = 255; + SET_REG_FIELD(0, gx->bpMask, 8, 24, 0x0F); + gx->lpSize = 0; + SET_REG_FIELD(0, gx->lpSize, 8, 24, 0x22); + for (i = 0; i < 16; ++i) { + gx->tevc[i] = 0; + gx->teva[i] = 0; + gx->tref[i / 2] = 0; + gx->texmapId[i] = GX_TEXMAP_NULL; + SET_REG_FIELD(0x2F2, gx->tevc[i], 8, 24, 0xC0 + i * 2); + SET_REG_FIELD(0x2F3, gx->teva[i], 8, 24, 0xC1 + i * 2); + SET_REG_FIELD(0x2F5, gx->tevKsel[i / 2], 8, 24, 0xF6 + i / 2); + SET_REG_FIELD(0x2F7, gx->tref[i / 2], 8, 24, 0x28 + i / 2); + } + gx->iref = 0; + SET_REG_FIELD(0, gx->iref, 8, 24, 0x27); + for (i = 0; i < 8; ++i) { + gx->suTs0[i] = 0; + gx->suTs1[i] = 0; + SET_REG_FIELD(0x300, gx->suTs0[i], 8, 24, 0x30 + i * 2); + SET_REG_FIELD(0x301, gx->suTs1[i], 8, 24, 0x31 + i * 2); + } + SET_REG_FIELD(0, gx->suScis0, 8, 24, 0x20); + SET_REG_FIELD(0, gx->suScis1, 8, 24, 0x21); + SET_REG_FIELD(0, gx->cmode0, 8, 24, 0x41); + SET_REG_FIELD(0, gx->cmode1, 8, 24, 0x42); + SET_REG_FIELD(0, gx->zmode, 8, 24, 0x40); + SET_REG_FIELD(0, gx->peCtrl, 8, 24, 0x43); + SET_REG_FIELD(0, gx->cpTex, 2, 7, 0); + gx->dirtyState = 0; + gx->dirtyVAT = FALSE; - // if (!resetFuncRegistered) { - // OSRegisterResetFunction(&GXResetFuncInfo); - // resetFuncRegistered = 1; - // } + freqBase = __OSBusClock / 500; + __GXFlushTextureState(); + reg = (freqBase >> 11) | 0x400 | 0x69000000; + GX_WRITE_RAS_REG(reg); - // __GXPEInit(); - // EnableWriteGatherPipe(); + __GXFlushTextureState(); + reg = (freqBase / 0x1080) | 0x200 | 0x46000000; + GX_WRITE_RAS_REG(reg); - gx->genMode = 0; - SET_REG_FIELD(0, gx->genMode, 8, 24, 0); - gx->bpMask = 255; - SET_REG_FIELD(0, gx->bpMask, 8, 24, 0x0F); - gx->lpSize = 0; - SET_REG_FIELD(0, gx->lpSize, 8, 24, 0x22); - for (i = 0; i < 16; ++i) { - gx->tevc[i] = 0; - gx->teva[i] = 0; - gx->tref[i / 2] = 0; - gx->texmapId[i] = GX_TEXMAP_NULL; - SET_REG_FIELD(0x46A, gx->tevc[i], 8, 24, 0xC0 + i * 2); - SET_REG_FIELD(0x46B, gx->teva[i], 8, 24, 0xC1 + i * 2); - SET_REG_FIELD(0x46D, gx->tevKsel[i / 2], 8, 24, 0xF6 + i / 2); - SET_REG_FIELD(0x46F, gx->tref[i / 2], 8, 24, 0x28 + i / 2); - } - gx->iref = 0; - SET_REG_FIELD(0, gx->iref, 8, 24, 0x27); - for (i = 0; i < 8; ++i) { - gx->suTs0[i] = 0; - gx->suTs1[i] = 0; - SET_REG_FIELD(0x478, gx->suTs0[i], 8, 24, 0x30 + i * 2); - SET_REG_FIELD(0x479, gx->suTs1[i], 8, 24, 0x31 + i * 2); - } - SET_REG_FIELD(0, gx->suScis0, 8, 24, 0x20); - SET_REG_FIELD(0, gx->suScis1, 8, 24, 0x21); - SET_REG_FIELD(0, gx->cmode0, 8, 24, 0x41); - SET_REG_FIELD(0, gx->cmode1, 8, 24, 0x42); - SET_REG_FIELD(0, gx->zmode, 8, 24, 0x40); - SET_REG_FIELD(0, gx->peCtrl, 8, 24, 0x43); - SET_REG_FIELD(0, gx->cpTex, 2, 7, 0); + for (i = GX_VTXFMT0; i < GX_MAX_VTXFMT; i++) { + SET_REG_FIELD(0, gx->vatA[i], 1, 30, 1); + SET_REG_FIELD(0, gx->vatB[i], 1, 31, 1); + do { + s32 regAddr; + GX_WRITE_U8(GX_LOAD_CP_REG); + GX_WRITE_U8(i | 0x80); + GX_WRITE_U32(gx->vatB[i]); + regAddr = i - 12; + } while (0); + } + { + u32 reg1 = 0; + u32 reg2 = 0; + SET_REG_FIELD(0, reg1, 1, 0, 1); + SET_REG_FIELD(0, reg1, 1, 1, 1); + SET_REG_FIELD(0, reg1, 1, 2, 1); + SET_REG_FIELD(0, reg1, 1, 3, 1); + SET_REG_FIELD(0, reg1, 1, 4, 1); + SET_REG_FIELD(0, reg1, 1, 5, 1); + GX_WRITE_XF_REG(0, reg1); + SET_REG_FIELD(0, reg2, 1, 0, 1); + GX_WRITE_XF_REG(0x12, reg2); + } + { + u32 reg = 0; + SET_REG_FIELD(0, reg, 1, 0, 1); + SET_REG_FIELD(0, reg, 1, 1, 1); + SET_REG_FIELD(0, reg, 1, 2, 1); + SET_REG_FIELD(0, reg, 1, 3, 1); + SET_REG_FIELD(0, reg, 8, 24, 0x58); + GX_WRITE_RAS_REG(reg); + } + for (i = 0; i < 8; i++) + GXInitTexCacheRegion(&gx->TexRegions[i], 0, i * 0x8000, 0, + 0x80000 + i * 0x8000, 0); + for (i = 0; i < 4; i++) + GXInitTexCacheRegion(&gx->TexRegionsCI[i], 0, (i * 2 + 8) * 0x8000, 0, + (i * 2 + 9) * 0x8000, 0); + for (i = 0; i < 16; i++) + GXInitTlutRegion(&gx->TlutRegions[i], 0xC0000 + i * 0x2000, 16); + for (i = 0; i < 4; i++) + GXInitTlutRegion(&gx->TlutRegions[i + 16], 0xE0000 + i * 0x8000, 64); + __cpReg[3] = 0; - // gx->zScale = 1.6777216E7f; - // gx->zOffset = 0.0f; - gx->dirtyState = 0; - gx->dirtyVAT = FALSE; -#if DEBUG - __gxVerif->verifyLevel = GX_WARN_NONE; - GXSetVerifyCallback((GXVerifyCallback)__GXDefaultVerifyCallback); - for (i = 0; i < 256; i++) { - SET_REG_FIELD(0, __gxVerif->rasRegs[i], 8, 24, 0xFF); - } - memset(__gxVerif->xfRegsDirty, 0, 0x50); - memset(__gxVerif->xfMtxDirty, 0, 0x100); - memset(__gxVerif->xfNrmDirty, 0, 0x60); - memset(__gxVerif->xfLightDirty, 0, 0x80); -#endif - freqBase = __OSBusClock / 500; - // __GXFlushTextureState(); - reg = (freqBase >> 11) | 0x400 | 0x69000000; - GX_WRITE_RAS_REG(reg); + { + SET_REG_FIELD(0, gx->perfSel, 4, 4, 0); + GX_WRITE_U8(GX_LOAD_CP_REG); + GX_WRITE_U8(0x20); + GX_WRITE_U32(gx->perfSel); + GX_WRITE_U8(GX_LOAD_XF_REG); + GX_WRITE_U32(0x1006); + GX_WRITE_U32(0); + GX_WRITE_RAS_REG(0x23000000); + GX_WRITE_RAS_REG(0x24000000); + GX_WRITE_RAS_REG(0x67000000); + } - // __GXFlushTextureState(); - reg = (freqBase / 0x1080) | 0x200 | 0x46000000; - GX_WRITE_RAS_REG(reg); - - // __GXInitRevisionBits(); - - // for (i = 0; i < 8; i++) { - // GXInitTexCacheRegion(&gx->TexRegions0[i], GX_FALSE, GXTexRegionAddrTable[i], - // GX_TEXCACHE_32K, GXTexRegionAddrTable[i + 8], GX_TEXCACHE_32K); - // GXInitTexCacheRegion(&gx->TexRegions1[i], GX_FALSE, GXTexRegionAddrTable[i + 16], - // GX_TEXCACHE_32K, GXTexRegionAddrTable[i + 24], GX_TEXCACHE_32K); - // GXInitTexCacheRegion(&gx->TexRegions2[i], GX_TRUE, GXTexRegionAddrTable[i + 32], - // GX_TEXCACHE_32K, GXTexRegionAddrTable[i + 40], GX_TEXCACHE_32K); - // } - - // for (i = 0; i < 16; i++) { - // GXInitTlutRegion(&gx->TlutRegions[i], 0xC0000 + 0x2000 * i, GX_TLUT_256); - // } - - // for (i = 0; i < 4; i++) { - // GXInitTlutRegion(&gx->TlutRegions[i + 16], 0xE0000 + 0x8000 * i, GX_TLUT_1K); - // } - - { - u32 reg = 0; -#if DEBUG - s32 regAddr; -#endif - GX_SET_CP_REG(3, reg); - - SET_REG_FIELD(0, gx->perfSel, 4, 4, 0); - GX_WRITE_U8(0x8); - GX_WRITE_U8(0x20); - GX_WRITE_U32(gx->perfSel); -#if DEBUG - regAddr = -12; -#endif - - reg = 0; - GX_WRITE_XF_REG(6, reg); - - reg = 0x23000000; - GX_WRITE_RAS_REG(reg); - - reg = 0x24000000; - GX_WRITE_RAS_REG(reg); - - reg = 0x67000000; - GX_WRITE_RAS_REG(reg); - } - - __GXSetIndirectMask(0); - __GXSetTmemConfig(2); - __GXInitGX(); - - return &FifoObj; + __GXSetTmemConfig(0); + __GXInitGX(); + return &FifoObj; } void __GXInitGX() diff --git a/src/dolphin/mtx/mtx.c b/src/dolphin/mtx/mtx.c index a8f2bb06..eb16a64f 100644 --- a/src/dolphin/mtx/mtx.c +++ b/src/dolphin/mtx/mtx.c @@ -3,6 +3,8 @@ static f32 Unit01[] = { 0.0f, 1.0f }; extern f32 sinf(f32); +extern f32 cosf(f32); +extern f32 tanf(f32); void C_MTXIdentity(Mtx mtx) { @@ -648,12 +650,12 @@ void C_MTXRotRad(Mtx m, char axis, f32 rad) #ifdef GEKKO void PSMTXRotRad(Mtx m, char axis, f32 rad) { - // f32 sinA, cosA; + f32 sinA, cosA; - // sinA = sinf(rad); - // cosA = cosf(rad); + sinA = sinf(rad); + cosA = cosf(rad); - // PSMTXRotTrig(m, axis, sinA, cosA); + PSMTXRotTrig(m, axis, sinA, cosA); } #endif @@ -717,68 +719,63 @@ void C_MTXRotTrig(Mtx m, char axis, f32 sinA, f32 cosA) #ifdef GEKKO void PSMTXRotTrig(register Mtx m, register char axis, register f32 sinA, register f32 cosA) { -// register f32 fc0, fc1, nsinA; -// register f32 fw0, fw1, fw2, fw3; -// // clang-format off -// asm -// { -// frsp sinA, sinA -// frsp cosA, cosA -// } + register f32 fc0, fc1, nsinA; + register f32 fw0, fw1, fw2, fw3; + // clang-format off -// fc0 = 0.0F; -// fc1 = 1.0F; -// asm -// { -// ori axis, axis, 0x20 -// ps_neg nsinA, sinA -// cmplwi axis, 'x' -// beq _case_x -// cmplwi axis, 'y' -// beq _case_y -// cmplwi axis, 'z' -// beq _case_z -// b _end + fc0 = 0.0F; + fc1 = 1.0F; + asm + { + ori axis, axis, 0x20 + ps_neg nsinA, sinA + cmplwi axis, 'x' + beq _case_x + cmplwi axis, 'y' + beq _case_y + cmplwi axis, 'z' + beq _case_z + b _end -// _case_x: -// psq_st fc1, 0(m), 1, 0 -// psq_st fc0, 4(m), 0, 0 -// ps_merge00 fw0, sinA, cosA -// psq_st fc0, 12(m), 0, 0 -// ps_merge00 fw1, cosA, nsinA -// psq_st fc0, 28(m), 0, 0 -// psq_st fc0, 44(m), 1, 0 -// psq_st fw0, 36(m), 0, 0 -// psq_st fw1, 20(m), 0, 0 -// b _end; +_case_x: + psq_st fc1, 0(m), 1, 0 + psq_st fc0, 4(m), 0, 0 + ps_merge00 fw0, sinA, cosA + psq_st fc0, 12(m), 0, 0 + ps_merge00 fw1, cosA, nsinA + psq_st fc0, 28(m), 0, 0 + psq_st fc0, 44(m), 1, 0 + psq_st fw0, 36(m), 0, 0 + psq_st fw1, 20(m), 0, 0 + b _end; -// _case_y: -// ps_merge00 fw0, cosA, fc0 -// ps_merge00 fw1, fc0, fc1 -// psq_st fc0, 24(m), 0, 0 -// psq_st fw0, 0(m), 0, 0 -// ps_merge00 fw2, nsinA, fc0 -// ps_merge00 fw3, sinA, fc0 -// psq_st fw0, 40(m), 0, 0; -// psq_st fw1, 16(m), 0, 0; -// psq_st fw3, 8(m), 0, 0; -// psq_st fw2, 32(m), 0, 0; -// b _end; +_case_y: + ps_merge00 fw0, cosA, fc0 + ps_merge00 fw1, fc0, fc1 + psq_st fc0, 24(m), 0, 0 + psq_st fw0, 0(m), 0, 0 + ps_merge00 fw2, nsinA, fc0 + ps_merge00 fw3, sinA, fc0 + psq_st fw0, 40(m), 0, 0; + psq_st fw1, 16(m), 0, 0; + psq_st fw3, 8(m), 0, 0; + psq_st fw2, 32(m), 0, 0; + b _end; -// _case_z: -// psq_st fc0, 8(m), 0, 0 -// ps_merge00 fw0, sinA, cosA -// ps_merge00 fw2, cosA, nsinA -// psq_st fc0, 24(m), 0, 0 -// psq_st fc0, 32(m), 0, 0 -// ps_merge00 fw1, fc1, fc0 -// psq_st fw0, 16(m), 0, 0 -// psq_st fw2, 0(m), 0, 0 -// psq_st fw1, 40(m), 0, 0 +_case_z: + psq_st fc0, 8(m), 0, 0 + ps_merge00 fw0, sinA, cosA + ps_merge00 fw2, cosA, nsinA + psq_st fc0, 24(m), 0, 0 + psq_st fc0, 32(m), 0, 0 + ps_merge00 fw1, fc1, fc0 + psq_st fw0, 16(m), 0, 0 + psq_st fw2, 0(m), 0, 0 + psq_st fw1, 40(m), 0, 0 -// _end: -// } -// // clang-format on +_end: + } + // clang-format on } #endif @@ -822,70 +819,58 @@ void C_MTXRotAxisRad(Mtx m, const Vec *axis, f32 rad) } #ifdef GEKKO -static void __PSMTXRotAxisRadInternal(register Mtx m, const register Vec *axis, register f32 sT, register f32 cT) +#define qr0 0 + +void PSMTXRotAxisRad(register Mtx m, const Vec *axis, register f32 rad) { - register f32 tT, fc0; register f32 tmp0, tmp1, tmp2, tmp3, tmp4; register f32 tmp5, tmp6, tmp7, tmp8, tmp9; - tmp9 = 0.5F; - tmp8 = 3.0F; - // clang-format off - asm - { - frsp cT, cT - psq_l tmp0, 0(axis), 0, 0 - frsp sT, sT - lfs tmp1, 8(axis) - ps_mul tmp2, tmp0, tmp0 - fadds tmp7, tmp9, tmp9 - ps_madd tmp3, tmp1, tmp1, tmp2 - fsubs fc0, tmp9, tmp9 - ps_sum0 tmp4, tmp3, tmp1, tmp2 - fsubs tT, tmp7, cT - frsqrte tmp5, tmp4 - fmuls tmp2, tmp5, tmp5 - fmuls tmp3, tmp5, tmp9 - fnmsubs tmp2, tmp2, tmp4, tmp8 - fmuls tmp5, tmp2, tmp3 - ps_merge00 cT, cT, cT - ps_muls0 tmp0, tmp0, tmp5 - ps_muls0 tmp1, tmp1, tmp5 - ps_muls0 tmp4, tmp0, tT - ps_muls0 tmp9, tmp0, sT - ps_muls0 tmp5, tmp1, tT - ps_muls1 tmp3, tmp4, tmp0 - ps_muls0 tmp2, tmp4, tmp0 - ps_muls0 tmp4, tmp4, tmp1 - fnmsubs tmp6, tmp1, sT, tmp3 - fmadds tmp7, tmp1, sT, tmp3 - ps_neg tmp0, tmp9 - ps_sum0 tmp8, tmp4, fc0, tmp9 - ps_sum0 tmp2, tmp2, tmp6, cT - ps_sum1 tmp3, cT, tmp7, tmp3 - ps_sum0 tmp6, tmp0, fc0 ,tmp4 - psq_st tmp8, 8(m), 0, 0 - ps_sum0 tmp0, tmp4, tmp4, tmp0 - psq_st tmp2, 0(m), 0, 0 - ps_muls0 tmp5, tmp5, tmp1 - psq_st tmp3, 16(m), 0, 0 - ps_sum1 tmp4, tmp9, tmp0, tmp4 - psq_st tmp6, 24(m), 0, 0 - ps_sum0 tmp5, tmp5, fc0, cT - psq_st tmp4, 32(m), 0, 0 - psq_st tmp5, 40(m), 0, 0 + register f32 sT; + register f32 cT; + register f32 oneMinusCosT; + register f32 zero; + Vec axisNormalized; + register Vec *axisNormalizedPtr; + + zero = 0.0f; + axisNormalizedPtr = &axisNormalized; + sT = sinf(rad); + cT = cosf(rad); + oneMinusCosT = 1.0f - cT; + + PSVECNormalize(axis, axisNormalizedPtr); + +#ifdef __MWERKS__ // clang-format off + asm { + psq_l rad, 0x0(axisNormalizedPtr), 0, qr0 + lfs tmp1, 0x8(axisNormalizedPtr) + ps_merge00 tmp0, cT, cT + ps_muls0 tmp4, rad, oneMinusCosT + ps_muls0 tmp5, tmp1, oneMinusCosT + ps_muls1 tmp3, tmp4, rad + ps_muls0 tmp2, tmp4, rad + ps_muls0 rad, rad, sT + ps_muls0 tmp4, tmp4, tmp1 + fnmsubs tmp6, tmp1, sT, tmp3 + fmadds tmp7, tmp1, sT, tmp3 + ps_neg tmp9, rad + ps_sum0 tmp8, tmp4, zero, rad + ps_sum0 tmp2, tmp2, tmp6, tmp0 + ps_sum1 tmp3, tmp0, tmp7, tmp3 + ps_sum0 tmp6, tmp9, zero, tmp4 + ps_sum0 tmp9, tmp4, tmp4, tmp9 + psq_st tmp8, 0x8(m), 0, qr0 + ps_muls0 tmp5, tmp5, tmp1 + psq_st tmp2, 0x0(m), 0, qr0 + ps_sum1 tmp4, rad, tmp9, tmp4 + psq_st tmp3, 0x10(m), 0, qr0 + ps_sum0 tmp5, tmp5, zero, tmp0 + psq_st tmp6, 0x18(m), 0, qr0 + psq_st tmp4, 0x20(m), 0, qr0 + psq_st tmp5, 0x28(m), 0, qr0 } - // clang-format on -} - -void PSMTXRotAxisRad(Mtx m, const Vec *axis, f32 rad) -{ - // f32 sinT, cosT; - - // sinT = sinf(rad); - // cosT = cosf(rad); - - // __PSMTXRotAxisRadInternal(m, axis, sinT, cosT); +#endif // clang-format on } #endif @@ -1219,30 +1204,30 @@ void PSMTXReflect(register Mtx m, const register Vec *p, const register Vec *n) void C_MTXLookAt(Mtx m, const Point3d *camPos, const Vec *camUp, const Point3d *target) { - // Vec vLook, vRight, vUp; + Vec vLook, vRight, vUp; - // vLook.x = camPos->x - target->x; - // vLook.y = camPos->y - target->y; - // vLook.z = camPos->z - target->z; - // VECNormalize(&vLook, &vLook); - // VECCrossProduct(camUp, &vLook, &vRight); - // VECNormalize(&vRight, &vRight); - // VECCrossProduct(&vLook, &vRight, &vUp); + vLook.x = camPos->x - target->x; + vLook.y = camPos->y - target->y; + vLook.z = camPos->z - target->z; + VECNormalize(&vLook, &vLook); + VECCrossProduct(camUp, &vLook, &vRight); + VECNormalize(&vRight, &vRight); + VECCrossProduct(&vLook, &vRight, &vUp); - // m[0][0] = vRight.x; - // m[0][1] = vRight.y; - // m[0][2] = vRight.z; - // m[0][3] = -(camPos->x * vRight.x + camPos->y * vRight.y + camPos->z * vRight.z); + m[0][0] = vRight.x; + m[0][1] = vRight.y; + m[0][2] = vRight.z; + m[0][3] = -(camPos->x * vRight.x + camPos->y * vRight.y + camPos->z * vRight.z); - // m[1][0] = vUp.x; - // m[1][1] = vUp.y; - // m[1][2] = vUp.z; - // m[1][3] = -(camPos->x * vUp.x + camPos->y * vUp.y + camPos->z * vUp.z); + m[1][0] = vUp.x; + m[1][1] = vUp.y; + m[1][2] = vUp.z; + m[1][3] = -(camPos->x * vUp.x + camPos->y * vUp.y + camPos->z * vUp.z); - // m[2][0] = vLook.x; - // m[2][1] = vLook.y; - // m[2][2] = vLook.z; - // m[2][3] = -(camPos->x * vLook.x + camPos->y * vLook.y + camPos->z * vLook.z); + m[2][0] = vLook.x; + m[2][1] = vLook.y; + m[2][2] = vLook.z; + m[2][3] = -(camPos->x * vLook.x + camPos->y * vLook.y + camPos->z * vLook.z); } void C_MTXLightFrustum(Mtx m, float t, float b, float l, float r, float n, float scaleS, float scaleT, float transS, float transT) @@ -1269,28 +1254,28 @@ void C_MTXLightFrustum(Mtx m, float t, float b, float l, float r, float n, float void C_MTXLightPerspective(Mtx m, f32 fovY, f32 aspect, float scaleS, float scaleT, float transS, float transT) { - // f32 angle; - // f32 cot; + f32 angle; + f32 cot; - // angle = fovY * 0.5f; - // angle = MTXDegToRad(angle); + angle = fovY * 0.5f; + angle = MTXDegToRad(angle); - // cot = 1.0f / tanf(angle); + cot = 1.0f / tanf(angle); - // m[0][0] = (cot / aspect) * scaleS; - // m[0][1] = 0.0f; - // m[0][2] = -transS; - // m[0][3] = 0.0f; + m[0][0] = (cot / aspect) * scaleS; + m[0][1] = 0.0f; + m[0][2] = -transS; + m[0][3] = 0.0f; - // m[1][0] = 0.0f; - // m[1][1] = cot * scaleT; - // m[1][2] = -transT; - // m[1][3] = 0.0f; + m[1][0] = 0.0f; + m[1][1] = cot * scaleT; + m[1][2] = -transT; + m[1][3] = 0.0f; - // m[2][0] = 0.0f; - // m[2][1] = 0.0f; - // m[2][2] = -1.0f; - // m[2][3] = 0.0f; + m[2][0] = 0.0f; + m[2][1] = 0.0f; + m[2][2] = -1.0f; + m[2][3] = 0.0f; } void C_MTXLightOrtho(Mtx m, f32 t, f32 b, f32 l, f32 r, float scaleS, float scaleT, float transS, float transT) diff --git a/src/dolphin/mtx/quat.c b/src/dolphin/mtx/quat.c index 66964bf0..f3e15a87 100644 --- a/src/dolphin/mtx/quat.c +++ b/src/dolphin/mtx/quat.c @@ -1,3 +1,4 @@ +#include "dolphin/math.h" #include "dolphin/mtx.h" float acosf(float x); @@ -5,6 +6,28 @@ float acosf(float x); float sinf(float x); float cosf(float x); +void C_QUATAdd(const Quaternion *p, const Quaternion *q, Qtrn *r) +{ + r->x = p->x + q->x; + r->y = p->y + q->y; + r->z = p->z + q->z; + r->w = p->w + q->w; +} + +void PSQUATAdd(register const Quaternion *p, register const Quaternion *q, register Quaternion *r) +{ + asm { + psq_l f0, 0x0(r3), 0, 0 + psq_l f1, 0x0(r4), 0, 0 + ps_add f0, f0, f1 + psq_st f0, 0x0(r5), 0, 0 + psq_l f0, 0x8(r3), 0, 0 + psq_l f1, 0x8(r4), 0, 0 + ps_add f0, f0, f1 + psq_st f0, 0x8(r5), 0, 0 + } +} + void PSQUATMultiply(register const Quaternion *a, register const Quaternion *b, register Quaternion *ab) { asm { @@ -33,6 +56,77 @@ void PSQUATMultiply(register const Quaternion *a, register const Quaternion *b, } } +void PSQUATNormalize(const register Quaternion *src, register Quaternion *unit) +{ + // sdata2 + (void)0.00001f; + (void)0.0f; + (void)0.5; + (void)3.0; + (void)1.0f; + (void)0.5f; + (void)3.0f; + { + register f32 vv1, vv2, vv3; + register f32 vv4, vv5, vv6; + register f32 vv7, vv8; + register f32 vv9 = 0.00001f; + register f32 vvA = 0.5F; + register f32 vvB = 3.0F; + asm + { + psq_l vv1, 0(src), 0, 0; + ps_mul vv3, vv1, vv1; + psq_l vv2, 8(src), 0, 0; + ps_sub vv6, vv9, vv9; + ps_madd vv3, vv2, vv2, vv3; + ps_sum0 vv3, vv3, vv3, vv3; + frsqrte vv4, vv3; + ps_sub vv5, vv3, vv9; + fmul vv7, vv4, vv4; + fmul vv8, vv4, vvA; + fnmsub vv7, vv7, vv3, vvB; + fmul vv4, vv7, vv8; + ps_sel vv4, vv5, vv4, vv6; + ps_muls0 vv1, vv1, vv4; + ps_muls0 vv2, vv2, vv4; + psq_st vv1, 0(unit), 0, 0; + psq_st vv2, 8(unit), 0, 0; + } + } +} + +void PSQUATInverse(const register Quaternion *src, register Quaternion *inv) +{ + register f32 vv1, vv2, vv3, vv4; + register f32 vv5, vv6, vv7, vv8, vv9, vvA, vvB; + register f32 vvC = 1.0F; + asm { + psq_l vv1, 0(src), 0, 0; + ps_mul vv5, vv1, vv1; + psq_l vv2, 8(src), 0, 0; + ps_madd vv5, vv2, vv2, vv5; + ps_add vvA, vvC, vvC; + ps_sum0 vv5, vv5, vv5, vv5; + fres vv7, vv5; + ps_neg vv6, vv5; + ps_nmsub vv9, vv5, vv7, vvA; + ps_mul vv7, vv7, vv9; + ps_sel vv7, vv6, vvC, vv7 + b loc1; + loc0: + fmr vv7, vvC; + loc1: + ps_neg vv8, vv7; + ps_muls1 vv4, vv7, vv2; + ps_muls0 vv1, vv1, vv8; + psq_st vv4, 12(inv), 1, 0; + ps_muls0 vv3, vv2, vv8; + psq_st vv1, 0(inv), 0, 0; + psq_st vv3, 8(inv), 1, 0; + } +} + void C_QUATRotAxisRad(Quaternion *q, const Vec *axis, f32 rad) { f32 tmp, tmp2, tmp3; @@ -52,6 +146,42 @@ void C_QUATRotAxisRad(Quaternion *q, const Vec *axis, f32 rad) q->w = tmp3; } +void C_QUATMtx(Quaternion *r, const Mtx m) +{ + f32 vv0, vv1; + s32 i, j, k; + s32 idx[3] = { 1, 2, 0 }; + f32 vec[3]; + vv0 = m[0][0] + m[1][1] + m[2][2]; + if (vv0 > 0.0f) { + vv1 = (f32)sqrtf(vv0 + 1.0f); + r->w = vv1 * 0.5f; + vv1 = 0.5f / vv1; + r->x = (m[2][1] - m[1][2]) * vv1; + r->y = (m[0][2] - m[2][0]) * vv1; + r->z = (m[1][0] - m[0][1]) * vv1; + } + else { + i = 0; + if (m[1][1] > m[0][0]) + i = 1; + if (m[2][2] > m[i][i]) + i = 2; + j = idx[i]; + k = idx[j]; + vv1 = (f32)sqrtf((m[i][i] - (m[j][j] + m[k][k])) + 1.0f); + vec[i] = vv1 * 0.5f; + if (vv1 != 0.0f) + vv1 = 0.5f / vv1; + r->w = (m[k][j] - m[j][k]) * vv1; + vec[j] = (m[i][j] + m[j][i]) * vv1; + vec[k] = (m[i][k] + m[k][i]) * vv1; + r->x = vec[0]; + r->y = vec[1]; + r->z = vec[2]; + } +} + void C_QUATSlerp(const Quaternion *p, const Quaternion *q, Quaternion *r, f32 t) { f32 ratioA, ratioB; diff --git a/src/dolphin/mtx/vec.c b/src/dolphin/mtx/vec.c index 985a6196..de5ad450 100644 --- a/src/dolphin/mtx/vec.c +++ b/src/dolphin/mtx/vec.c @@ -210,23 +210,23 @@ void C_VECHalfAngle(const Vec *a, const Vec *b, Vec *half) void C_VECReflect(const Vec *src, const Vec *normal, Vec *dst) { - // Vec a0; - // Vec b0; - // f32 dot; + Vec a0; + Vec b0; + f32 dot; - // a0.x = -src->x; - // a0.y = -src->y; - // a0.z = -src->z; + a0.x = -src->x; + a0.y = -src->y; + a0.z = -src->z; - // VECNormalize(&a0, &a0); - // VECNormalize(normal, &b0); + VECNormalize(&a0, &a0); + VECNormalize(normal, &b0); - // dot = VECDotProduct(&a0, &b0); - // dst->x = b0.x * 2.0f * dot - a0.x; - // dst->y = b0.y * 2.0f * dot - a0.y; - // dst->z = b0.z * 2.0f * dot - a0.z; + dot = VECDotProduct(&a0, &b0); + dst->x = b0.x * 2.0f * dot - a0.x; + dst->y = b0.y * 2.0f * dot - a0.y; + dst->z = b0.z * 2.0f * dot - a0.z; - // VECNormalize(dst, dst); + VECNormalize(dst, dst); } asm f32 PSVECSquareDistance(register const Vec *a, register const Vec *b) { diff --git a/src/dolphin/pad/Padclamp.c b/src/dolphin/pad/Padclamp.c index a96d75c4..bdc9af39 100644 --- a/src/dolphin/pad/Padclamp.c +++ b/src/dolphin/pad/Padclamp.c @@ -103,17 +103,34 @@ static void ClampTrigger(u8 *trigger, u8 min, u8 max) } } -void PADClamp(PADStatus *status) +void PADClamp(PADStatus* status) { - // int i; - // for (i = 0; i < PAD_CHANMAX; i++, status++) { - // if (status->err != PAD_ERR_NONE) { - // continue; - // } + int i; + for (i = 0; i < PAD_CHANMAX; i++, status++) { + if (status->err != PAD_ERR_NONE) { + continue; + } - // ClampStick(&status->stickX, &status->stickY, ClampRegion.maxStick, ClampRegion.xyStick, ClampRegion.minStick); - // ClampStick(&status->substickX, &status->substickY, ClampRegion.maxSubstick, ClampRegion.xySubstick, ClampRegion.minSubstick); - // ClampTrigger(&status->triggerL, ClampRegion.minTrigger, ClampRegion.maxTrigger); - // ClampTrigger(&status->triggerR, ClampRegion.minTrigger, ClampRegion.maxTrigger); - // } + ClampStick(&status->stickX, &status->stickY, ClampRegion.maxStick, + ClampRegion.xyStick, ClampRegion.minStick); + ClampStick(&status->substickX, &status->substickY, + ClampRegion.maxSubstick, ClampRegion.xySubstick, + ClampRegion.minSubstick); + if (status->triggerL <= ClampRegion.minTrigger) { + status->triggerL = 0; + } else { + if (ClampRegion.maxTrigger < status->triggerL) { + status->triggerL = ClampRegion.maxTrigger; + } + status->triggerL -= ClampRegion.minTrigger; + } + if (status->triggerR <= ClampRegion.minTrigger) { + status->triggerR = 0; + } else { + if (ClampRegion.maxTrigger < status->triggerR) { + status->triggerR = ClampRegion.maxTrigger; + } + status->triggerR -= ClampRegion.minTrigger; + } + } }