Created
June 1, 2023 02:42
-
-
Save Ziemas/385608ecd452431132979d68b04f7514 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "loadcore.h" | |
#include "stdio.h" | |
#include "thevent.h" | |
#include "thmsgbx.h" | |
#include "thpool.h" | |
#include "thsemap.h" | |
#include "xthbase.h" | |
IRX_ID("ThreadMonitor", 1, 0); | |
#define HANDLE_ID(handle) (((handle) >> 1) & 0x3f) | |
static const char ThreadStatus[] = "000RunRdy333Wat5556667"; | |
static const char ThreadWaitStatus[] = " SlDlSeEvMbVpFp "; | |
static int handles[128]; | |
static void list_fpool() | |
{ | |
iop_fpl_info_t fpl; | |
int count; | |
GetThreadmanIdList(6, handles, 128, &count); | |
printf(" FPLID ATTR OPTION BlkSIze AllBlocks FreeSize waitThreads"); | |
for (int i = 0; i < count; i++) { | |
if (ReferFplStatus(handles[i], &fpl) < 0) { | |
} | |
printf("%3d %06x %08x %08x %06x %06x %06x %5d\n", HANDLE_ID(handles[i]), handles[i], fpl.attr, fpl.option, fpl.blockSize, fpl.numBlocks, fpl.freeBlocks, fpl.numWaitThreads); | |
} | |
} | |
static void list_vpool() | |
{ | |
iop_vpl_info_t vpl; | |
int count; | |
GetThreadmanIdList(5, handles, 128, &count); | |
printf(" VPLID ATTR OPTION Size Free waitThreads\n"); | |
for (int i = 0; i < count; i++) { | |
if (ReferVplStatus(handles[i], &vpl) < 0) { | |
continue; | |
} | |
printf("%3d %06x %08x %08x %06x %06x %5d\n", HANDLE_ID(handles[i]), handles[i], vpl.attr, vpl.option, vpl.size, vpl.freeSize, vpl.numWaitThreads); | |
} | |
} | |
static void list_msgbx() | |
{ | |
iop_mbx_status_t mbx; | |
int count; | |
GetThreadmanIdList(4, handles, 128, &count); | |
printf(" MSGID ATTR OPTION waitThreads messages\n"); | |
for (int i = 0; i < count; i++) { | |
if (ReferMbxStatus(handles[i], &mbx) < 0) { | |
continue; | |
} | |
printf("%3d %06x %08x %08x %5d %5d\n", HANDLE_ID(handles[i]), handles[i], mbx.attr, mbx.option, mbx.numWaitThreads, mbx.numMessage); | |
} | |
} | |
static void list_eventflag() | |
{ | |
iop_event_info_t event; | |
int count; | |
GetThreadmanIdList(3, handles, 128, &count); | |
printf(" EVID ATTR OPTION iPattern cPattern waitThreads\n"); | |
for (int i = 0; i < count; i++) { | |
if (ReferEventFlagStatus(handles[i], &event) < 0) { | |
continue; | |
} | |
printf("%3d %06x %08x %08x %08x %08x %5d\n", HANDLE_ID(handles[i]), handles[i], event.attr, event.option, event.initBits, event.currBits, event.numThreads); | |
} | |
} | |
static void list_semaphores() | |
{ | |
iop_sema_info_t sema; | |
int count; | |
GetThreadmanIdList(2, handles, 128, &count); | |
printf(" SEMID ATTR OPTION iCnt cCnt mCnt waitThreads\n"); | |
for (int i = 0; i < count; i++) { | |
if (ReferSemaStatus(handles[i], &sema) < 0) { | |
continue; | |
} | |
printf("%3d %06x %08x %08x %05d %5d %5d %5d\n", | |
HANDLE_ID(handles[i]), handles[i], sema.attr, sema.option, sema.initial, sema.current, sema.max, sema.numWaitThreads); | |
} | |
} | |
static void list_threads() | |
{ | |
iop_thread_info_t thread; | |
int count; | |
GetThreadmanIdList(1, handles, 128, &count); | |
printf(" THID ATTR OPTION STS ENTRY STACK SSIZE GP CP IP WT WID WUC\n"); | |
for (int i = 0; i < count; i++) { | |
if (ReferThreadStatus(handles[i], &thread) < 0) { | |
continue; | |
} | |
printf("%3d %06x %08x %08x %.3s ", | |
HANDLE_ID(handles[i]), handles[i], thread.attr, thread.option, &ThreadStatus[(thread.status << 1) + thread.status]); | |
printf("%06x %06x %04x %06x %3d %3d %c%c %06x %2x\n", | |
thread.entry, thread.stack, thread.stackSize, thread.gpReg, thread.currentPriority, thread.initPriority, ThreadWaitStatus[thread.waitType << 1], ThreadWaitStatus[(thread.waitType << 1) + 1], thread.waitId, thread.wakeupCount); | |
if (thread.regContext != NULL) { | |
if (thread.status != THS_DORMANT) { | |
printf(" PC=%06x RA=%06x SP=%06x Context_addr/mask=%08x/%08x\n", thread.regContext[0x23], thread.regContext[0x1F], thread.regContext[0x1D], thread.regContext, thread.regContext[0]); | |
} | |
} | |
} | |
} | |
int _start(void* argp) | |
{ | |
list_threads(); | |
list_semaphores(); | |
list_eventflag(); | |
list_msgbx(); | |
list_vpool(); | |
list_fpool(); | |
return MODULE_RESIDENT_END; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment