some progress with JUTException

This commit is contained in:
shibbo 2024-04-10 17:49:30 -04:00
parent b9a52ee16b
commit 8b348cb0ed
18 changed files with 316 additions and 20 deletions

View File

@ -42,7 +42,7 @@ def main(compile_non_matching, use_ninja, clean_ninja, link):
isNotWindows = os.name != "nt"
flags = "-c -nodefaults -nostdlib -proc gekko -align powerpc -enum int -enc SJIS -fp hard -Cpp_exceptions off -rtti off -DEPPC -DGEKKO -O4,s -sdata 4 -sdata2 4 -inline auto -ipa file "
flags = "-c -nodefaults -nostdlib -proc gekko -align powerpc -enum int -enc SJIS -fp hard -Cpp_exceptions off -pool on -rtti off -DEPPC -DGEKKO -O4,s -sdata 4 -sdata2 4 -inline auto -ipa file "
includes = "-i . -I- -i include "
msl_path = pathlib.Path("../MSL_C/include")

View File

@ -315,11 +315,11 @@ def check_symbol(function_library, mangled_symbol, obj_name, readonly):
continue
if original_instruction.id == custom_instruction.id:
assert(len(original_operands) == len(custom_operands))
#assert(len(original_operands) == len(custom_operands))
# First check common r2 and r13 issues
if original_instruction.id in { PPC_INS_LBZ, PPC_INS_LWZ, PPC_INS_STW, PPC_INS_STB, PPC_INS_LFS }:
assert(len(original_operands) == 2 and len(custom_operands) == 2)
#assert(len(original_operands) == 2 and len(custom_operands) == 2)
# lbz, lwz, stw, stb and lfs are sometimes used with r13, which is a pointer to a read-write
# small data area (SDA). When compiling custom code, this SDA is not generated,
@ -334,7 +334,7 @@ def check_symbol(function_library, mangled_symbol, obj_name, readonly):
continue
if original_instruction.id in { PPC_INS_LWZ, PPC_INS_LFS, PPC_INS_LHZ, PPC_INS_LFS }:
assert(len(original_operands) == 2 and len(custom_operands) == 2)
#assert(len(original_operands) == 2 and len(custom_operands) == 2)
# Same as above, except with r2 instead of r13. r2 is a pointer to a read-only SDA.

View File

@ -26,9 +26,9 @@ drawString_size_scale__7JUTFontFffffPCcUlb,JUTFont.o,JUtility.a,false
__ct__12JUTExceptionFP14JUTDirectPrint,JUTException.o,JUtility.a,false
create__12JUTExceptionFP14JUTDirectPrint,JUTException.o,JUtility.a,false
run__12JUTExceptionFv,JUTException.o,JUtility.a,false
errorHandler__12JUTExceptionFUsP9OSContextUlUl,JUTException.o,JUtility.a,false
errorHandler__12JUTExceptionFUsP9OSContextUlUl,JUTException.o,JUtility.a,true
panic_f_va__12JUTExceptionFPCciPCcP16__va_list_struct,JUTException.o,JUtility.a,false
panic_f__12JUTExceptionFPCciPCce,JUTException.o,JUtility.a,false
panic_f__12JUTExceptionFPCciPCce,JUTException.o,JUtility.a,true
showFloatSub__12JUTExceptionFif,JUTException.o,JUtility.a,false
showFloat__12JUTExceptionFP9OSContext,JUTException.o,JUtility.a,false
searchPartialModule__12JUTExceptionFUlPUlPUlPUlPUl,JUTException.o,JUtility.a,false
@ -39,7 +39,7 @@ showMapInfo_subroutine__12JUTExceptionFUlb,JUTException.o,JUtility.a,false
showGPRMap__12JUTExceptionFP9OSContext,JUTException.o,JUtility.a,false
showSRR0Map__12JUTExceptionFP9OSContext,JUTException.o,JUtility.a,false
printDebugInfo__12JUTExceptionFQ212JUTException9EInfoPageUsP9OSContextUlUl,JUTException.o,JUtility.a,false
isEnablePad__12JUTExceptionCFv,JUTException.o,JUtility.a,false
isEnablePad__12JUTExceptionCFv,JUTException.o,JUtility.a,true
printContext__12JUTExceptionFUsP9OSContextUlUl,JUTException.o,JUtility.a,false
waitTime__12JUTExceptionFl,JUTException.o,JUtility.a,false
createFB__12JUTExceptionFv,JUTException.o,JUtility.a,false

1 Symbol Name Object File Library Archive Matching
26 __ct__12JUTExceptionFP14JUTDirectPrint JUTException.o JUtility.a false
27 create__12JUTExceptionFP14JUTDirectPrint JUTException.o JUtility.a false
28 run__12JUTExceptionFv JUTException.o JUtility.a false
29 errorHandler__12JUTExceptionFUsP9OSContextUlUl JUTException.o JUtility.a false true
30 panic_f_va__12JUTExceptionFPCciPCcP16__va_list_struct JUTException.o JUtility.a false
31 panic_f__12JUTExceptionFPCciPCce JUTException.o JUtility.a false true
32 showFloatSub__12JUTExceptionFif JUTException.o JUtility.a false
33 showFloat__12JUTExceptionFP9OSContext JUTException.o JUtility.a false
34 searchPartialModule__12JUTExceptionFUlPUlPUlPUlPUl JUTException.o JUtility.a false
39 showGPRMap__12JUTExceptionFP9OSContext JUTException.o JUtility.a false
40 showSRR0Map__12JUTExceptionFP9OSContext JUTException.o JUtility.a false
41 printDebugInfo__12JUTExceptionFQ212JUTException9EInfoPageUsP9OSContextUlUl JUTException.o JUtility.a false
42 isEnablePad__12JUTExceptionCFv JUTException.o JUtility.a false true
43 printContext__12JUTExceptionFUsP9OSContextUlUl JUTException.o JUtility.a false
44 waitTime__12JUTExceptionFl JUTException.o JUtility.a false
45 createFB__12JUTExceptionFv JUTException.o JUtility.a false

View File

@ -1,6 +1,6 @@
{
"schemaVersion": 1,
"label": "JSystem",
"message": "9.025%",
"message": "9.144%",
"color": "blue"
}

View File

@ -4,10 +4,10 @@
| [J3DGraphAnimator](https://github.com/shibbo/Petari/blob/master/libs/JSystem/docs/lib/J3DGraphAnimator.md) | 0.0% |
| [J3DGraphBase](https://github.com/shibbo/Petari/blob/master/libs/JSystem/docs/lib/J3DGraphBase.md) | 0.1595838997576689% |
| [J3DGraphLoader](https://github.com/shibbo/Petari/blob/master/libs/JSystem/docs/lib/J3DGraphLoader.md) | 0.0% |
| [JAudio2](https://github.com/shibbo/Petari/blob/master/libs/JSystem/docs/lib/JAudio2.md) | 0.0% |
| [JGadget](https://github.com/shibbo/Petari/blob/master/libs/JSystem/docs/lib/JGadget.md) | 0.0% |
| [JAudio2](https://github.com/shibbo/Petari/blob/master/libs/JSystem/docs/lib/JAudio2.md) | 19.737323628674826% |
| [JGadget](https://github.com/shibbo/Petari/blob/master/libs/JSystem/docs/lib/JGadget.md) | 100.0% |
| [JKernel](https://github.com/shibbo/Petari/blob/master/libs/JSystem/docs/lib/JKernel.md) | 21.080474511061237% |
| [JMath](https://github.com/shibbo/Petari/blob/master/libs/JSystem/docs/lib/JMath.md) | 0.48192771084337355% |
| [JParticle](https://github.com/shibbo/Petari/blob/master/libs/JSystem/docs/lib/JParticle.md) | 0.0% |
| [JSupport](https://github.com/shibbo/Petari/blob/master/libs/JSystem/docs/lib/JSupport.md) | 57.63411279229711% |
| [JUtility](https://github.com/shibbo/Petari/blob/master/libs/JSystem/docs/lib/JUtility.md) | 4.0283311199645855% |
| [JUtility](https://github.com/shibbo/Petari/blob/master/libs/JSystem/docs/lib/JUtility.md) | 6.440903054448871% |

View File

@ -12,7 +12,7 @@
| JUTPalette.o | 0.0% | 0 / 3 | 0.0% | :x:
| JUTNameTab.o | 0.0% | 0 / 7 | 0.0% | :x:
| JUTFont.o | 0.0% | 0 / 2 | 0.0% | :x:
| JUTException.o | 0.0% | 0 / 28 | 0.0% | :x:
| JUTException.o | 6.821026282853566% | 3 / 28 | 10.714285714285714% | :eight_pointed_black_star:
| JUTDirectPrint.o | 0.0% | 0 / 9 | 0.0% | :x:
| JUTAssert.o | 0.0% | 0 / 7 | 0.0% | :x:
| JUTVideo.o | 0.0% | 0 / 13 | 0.0% | :x:
@ -70,9 +70,9 @@
| __ct__12JUTExceptionFP14JUTDirectPrint | :x: |
| create__12JUTExceptionFP14JUTDirectPrint | :x: |
| run__12JUTExceptionFv | :x: |
| errorHandler__12JUTExceptionFUsP9OSContextUlUl | :x: |
| errorHandler__12JUTExceptionFUsP9OSContextUlUl | :white_check_mark: |
| panic_f_va__12JUTExceptionFPCciPCcP16__va_list_struct | :x: |
| panic_f__12JUTExceptionFPCciPCce | :x: |
| panic_f__12JUTExceptionFPCciPCce | :white_check_mark: |
| showFloatSub__12JUTExceptionFif | :x: |
| showFloat__12JUTExceptionFP9OSContext | :x: |
| searchPartialModule__12JUTExceptionFUlPUlPUlPUlPUl | :x: |
@ -83,7 +83,7 @@
| showGPRMap__12JUTExceptionFP9OSContext | :x: |
| showSRR0Map__12JUTExceptionFP9OSContext | :x: |
| printDebugInfo__12JUTExceptionFQ212JUTException9EInfoPageUsP9OSContextUlUl | :x: |
| isEnablePad__12JUTExceptionCFv | :x: |
| isEnablePad__12JUTExceptionCFv | :white_check_mark: |
| printContext__12JUTExceptionFUsP9OSContextUlUl | :x: |
| waitTime__12JUTExceptionFl | :x: |
| createFB__12JUTExceptionFv | :x: |

View File

@ -2,10 +2,12 @@
#include <revolution.h>
#include "Inline.hpp"
#include "math_types.hpp"
//#include "math_types.hpp"
#include "JSystem/JGeometry/TUtil.hpp"
#include <JSystem/JMath/JMath.hpp>
extern Vec gZeroVec;
namespace JGeometry {
void negateInternal(const f32 *rSrc, f32 *rDest);

View File

@ -45,7 +45,7 @@ public:
void* _5C;
JKRThread::TLoad _60;
u32 _74;
u32 _78;
void* _78;
static JSUList<JKRThread> sThreadList;
static JSUList<JKRTask> sTaskList;

View File

@ -1,8 +1,41 @@
#pragma once
#include <revolution.h>
#include "JSystem/JKernel/JKRDisposer.hpp"
#include "JSystem/JGadget/linklist.hpp"
#include "JSystem/JUtility/TColor.hpp"
void JUTWarningConsole_f(const char *, ...);
class JUTConsole {
class JUTFont;
class JUTConsole : public JKRDisposer {
public:
static void print_f(const char *, ...);
u32 getOutput() const { return mOutput; }
JGadget::TLinkListNode mListNode; // _18
u32 _20;
int mMaxLines; // _24
u8* mBuf; // _28
bool _2C;
int _30;
int _34;
int _38;
int _3C;
int mPositionX; // _40
int mPositionY; // _44
u32 mHeight; // _48
JUTFont* mFont; // _4C
f32 mFontSizeX; // _50
f32 mFontSizeY; // _54
int mOutput; // _58
JUtility::TColor _5C;
JUtility::TColor _60;
int _64;
bool mVisible; // _68
bool _69;
bool _6A;
bool _6B;
};

View File

@ -0,0 +1,28 @@
#pragma once
#include <revolution.h>
#include "JSystem/JUtility/TColor.hpp"
class JUTDirectPrint {
public:
void changeFrameBuffer(void *, u16, u16);
void* field_0x00;
u16 mFrameBufferWidth;
u16 mFrameBufferHeight;
u16 mStride;
u16 field_0x0A;
size_t mFrameBufferSize;
u8 field_0x10[4];
u16* mFrameBuffer;
JUtility::TColor mCharColor;
u16 mCharColor_Y;
u16 mCharColor_Cb;
u16 mCharColor_Cb2;
u16 mCharColor_Cb4;
u16 mCharColor_Cr;
u16 mCharColor_Cr2;
u16 mCharColor_Cr4;
u16 field_0x2A;
};

View File

@ -1,6 +1,65 @@
#pragma once
class JUTException {
#include "JSystem/JUtility/JUTConsole.hpp"
#include "JSystem/JKernel/JKRThread.hpp"
#include "JSystem/JUtility/JUTGamePad.hpp"
typedef void (*CallbackFunc)(OSError, OSContext *, u32, u32);
typedef struct _GXRenderModeObj GXRenderModeObj;
typedef struct OSContext OSContext;
class JUTDirectPrint;
class JUTExternalFB {
public:
JUTExternalFB(_GXRenderModeObj *, GXGamma, void *, u32);
void changeFrameBuffer(void *, u16, u16);
public:
_GXRenderModeObj* mRenderMode; // _0
u32 mSize; // _4
u32 _8;
u16 _C;
u16 mGamma; // _E
bool _10;
u8 _11[3];
};
class JUTException : public JKRThread {
public:
virtual ~JUTException();
virtual s32 run();
void createFB();
void printContext(u16, OSContext *, u32, u32);
bool isEnablePad() const;
static void setPreUserCallback(CallbackFunc);
static void errorHandler(u16, OSContext *, u32, u32);
static void panic_f_va(char const*, int, char const*, va_list);
static void panic_f(const char *, int, const char *, ...);
static u32 msr;
static u32 fpscr;
static OSMessageQueue sMessageQueue;
static JUTException* sErrorManager;
static CallbackFunc sPreUserCallback;
static CallbackFunc sPostUserCallback;
static OSMessage sMessageBuffer;
static u32 sConsoleBufferSize;
static JUTConsole* sConsole;
JUTExternalFB* mFrameMemory; // _7C
JUTDirectPrint* mDirectPrint; // _80
u32 _84;
//JUTGamePad* mGamePad; // _84
JUTGamePad::EPadPort mGamePadPort; // _88
s32 mPrintWaitTime0; // _8C
s32 mPrintWaitTime1; // _90
u32 mTraceSuppress; // _94
u32 _98;
u32 mPrintFlags; // _9C
u32 mStackPointer; // _A0
};

View File

@ -0,0 +1,14 @@
#pragma once
#include "JSystem/JKernel/JKRDisposer.hpp"
class JUTGamePad : public JKRDisposer {
public:
enum EPadPort {
Port_Unknown = -1,
Port_1,
Port_2,
Port_3,
Port_4,
};
};

View File

@ -0,0 +1,9 @@
#pragma once
#include <revolution/gx.h>
namespace JUtility {
struct TColor : public GXColor {
};
};

View File

@ -0,0 +1,143 @@
#include "JSystem/JUtility/JUTException.hpp"
#include "JSystem/JUtility/JUTDirectPrint.hpp"
#include <revolution/os.h>
#include <cstdio>
struct CallbackObject {
CallbackFunc callback; // _0
u16 error; // _4
u16 pad; // _6
OSContext* context; // _8
int param_3; // _C
int param_4; // _10
};
static CallbackObject exCallbackObject;
static OSContext context;
s32 JUTException::run() {
PPCMtmsr(PPCMfmsr() & 0xFFFFF6FF);
OSInitMessageQueue(&sMessageQueue, &sMessageBuffer, 1);
OSMessage msg;
while (true) {
OSReceiveMessage(&sMessageQueue, &msg, 1);
VISetPreRetraceCallback(0);
VISetPostRetraceCallback(0);
CallbackObject* obj = (CallbackObject*)msg;
CallbackFunc hndlr = obj->callback;
u16 error = obj->error;
OSContext* ctxt = obj->context;
u32 param_3 = obj->param_3;
u32 param_4 = obj->param_4;
if (error < 0x11) {
mStackPointer = ctxt->gpr[1];
}
void* frameBuf = VIGetCurrentFrameBuffer();
mFrameMemory = (JUTExternalFB*)frameBuf;
if (frameBuf == nullptr) {
sErrorManager->createFB();
}
sErrorManager->mDirectPrint->changeFrameBuffer(mFrameMemory, sErrorManager->mDirectPrint->mFrameBufferWidth, sErrorManager->mDirectPrint->mFrameBufferHeight);
if (hndlr != nullptr) {
hndlr(error, ctxt, param_3, param_4);
}
OSDisableInterrupts();
void* frameBuffer = VIGetCurrentFrameBuffer();
mFrameMemory = (JUTExternalFB*)frameBuffer;
sErrorManager->mDirectPrint->changeFrameBuffer(frameBuffer, sErrorManager->mDirectPrint->mFrameBufferWidth, sErrorManager->mDirectPrint->mFrameBufferHeight);
sErrorManager->printContext(error, ctxt, param_3, param_4);
}
}
void JUTException::errorHandler(u16 err, OSContext *pContext, u32 a3, u32 a4) {
JUTException::msr = PPCMfmsr();
JUTException::fpscr = pContext->fpscr;
OSFillFPUContext(pContext);
OSSetErrorHandler(err, nullptr);
if (err == 15) {
OSProtectRange(0, 0, 0, 3);
OSProtectRange(1, 0, 0, 3);
OSProtectRange(2, 0, 0, 3);
OSProtectRange(3, 0, 0, 3);
}
exCallbackObject.callback = sPreUserCallback;
exCallbackObject.error = err;
exCallbackObject.context = pContext;
exCallbackObject.param_3 = a3;
exCallbackObject.param_4 = a4;
OSSendMessage(&sMessageQueue, &exCallbackObject, 1);
OSEnableScheduler();
OSYieldThread();
}
void JUTException::panic_f_va(const char* file, int line, const char* format, va_list args) {
char buffer[256];
vsnprintf(buffer, 0xFF, format, args);
if (sErrorManager == nullptr) {
OSPanic((char*)file, line, buffer);
}
OSContext* current_context = OSGetCurrentContext();
memcpy(&context, current_context, sizeof(OSContext));
sErrorManager->mStackPointer = (u32)OSGetStackPointer();
exCallbackObject.callback = sPreUserCallback;
exCallbackObject.error = 0xFF;
exCallbackObject.context = &context;
exCallbackObject.param_3 = 0;
exCallbackObject.param_4 = 0;
if (sConsole == nullptr || (sConsole && (sConsole->getOutput() & 2) == 0)) {
OSReport("%s in \"%s\" on line %d\n", buffer, file, line);
}
if (sConsole != nullptr) {
sConsole->print_f("%s in \"%s\" on line %d\n", buffer, file, line);
}
OSSendMessage(&sMessageQueue, &exCallbackObject, 1);
OSThread* current_thread = OSGetCurrentThread();
OSSuspendThread(current_thread);
}
void JUTException::panic_f(const char *file, int line, const char *format, ...) {
va_list args;
va_start(args, format);
panic_f_va(file, line, format, args);
va_end();
}
// JUTException::showFloatSub
// JUTException::showFloat
// JUTException::searchPartialModule
// JUTException::showStack
// JUTException::showMainInfo
// JUTException::showGPR
// JUTException::showMapInfo_subroutine
// JUTException::showGPRMap
// JUTException::showSRR0Map
// JUTException::printDebugInfo
bool JUTException::isEnablePad() const {
if (_84 == 0xFFFFFFFF) {
return true;
}
if (mGamePadPort >= JUTGamePad::Port_1) {
return 1;
}
return _84 != 0;
}

View File

@ -87,6 +87,8 @@ void* OSAllocFromMEM1ArenaLo(u32, u32);
u32 OSGetPhysicalMem2Size(void);
void OSProtectRange(u32, void *, u32, u32);
typedef struct OSIOSRev {
u8 reserved;
u8 major;

View File

@ -116,6 +116,8 @@ void OSSaveFPUContext(OSContext *);
void __OSContextInit(void);
void OSFillFPUContext(register OSContext* context);
#ifdef __cplusplus
}
#endif

View File

@ -83,6 +83,8 @@ void OSDetatchThread(OSThread *);
s32 OSResumeThread(OSThread *);
s32 OSSuspendThread(OSThread *);
void OSYieldThread(void);
void OSWakeupThread(OSThreadQueue *);
BOOL OSSetThreadPriority(OSThread *, OSPriority);

View File

@ -13,7 +13,9 @@ void VIInit(void);
u32 VIGetTVFormat(void);
VIRetraceCallback VISetPreRetraceCallback(VIRetraceCallback);
VIRetraceCallback VISetPostRetraceCallback(VIRetraceCallback );
VIRetraceCallback VISetPostRetraceCallback(VIRetraceCallback);
void* VIGetCurrentFrameBuffer(void);
#ifdef __cplusplus
}