1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-14 13:30:47 +00:00
oot/src/boot/stackcheck.c

134 lines
3.3 KiB
C
Raw Normal View History

#include "global.h"
#include "vt.h"
2020-03-17 04:31:30 +00:00
StackEntry* sStackInfoListStart = NULL;
StackEntry* sStackInfoListEnd = NULL;
2020-03-22 21:19:43 +00:00
void StackCheck_Init(StackEntry* entry, void* stackTop, void* stackBottom, u32 initValue, s32 minSpace,
const char* name) {
2020-03-17 04:31:30 +00:00
StackEntry* iter;
u32* addr;
if (entry == NULL) {
2020-03-17 04:31:30 +00:00
sStackInfoListStart = NULL;
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
entry->head = (u32)stackTop;
entry->tail = (u32)stackBottom;
entry->initValue = initValue;
entry->minSpace = minSpace;
entry->name = name;
iter = sStackInfoListStart;
2020-03-22 21:19:43 +00:00
while (iter) {
if (iter == entry) {
2020-03-17 04:31:30 +00:00
osSyncPrintf(VT_COL(RED, WHITE) "stackcheck_init: %08x は既にリスト中にある\n" VT_RST, entry);
return;
}
iter = iter->next;
}
2020-03-22 21:19:43 +00:00
2020-03-17 04:31:30 +00:00
entry->prev = sStackInfoListEnd;
entry->next = NULL;
2020-03-22 21:19:43 +00:00
if (sStackInfoListEnd) {
2020-03-17 04:31:30 +00:00
sStackInfoListEnd->next = entry;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
sStackInfoListEnd = entry;
2020-03-22 21:19:43 +00:00
if (!sStackInfoListStart) {
2020-03-17 04:31:30 +00:00
sStackInfoListStart = entry;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
2020-03-22 21:19:43 +00:00
if (entry->minSpace != -1) {
2020-03-17 04:31:30 +00:00
addr = (u32*)entry->head;
2020-03-22 21:19:43 +00:00
while ((u32)addr < entry->tail) {
2020-03-17 04:31:30 +00:00
*addr++ = entry->initValue;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
}
}
}
2020-03-22 21:19:43 +00:00
void StackCheck_Cleanup(StackEntry* entry) {
2020-03-17 04:31:30 +00:00
bool inconsistency = false;
2020-03-22 21:19:43 +00:00
if (!entry->prev) {
if (entry == sStackInfoListStart) {
2020-03-17 04:31:30 +00:00
sStackInfoListStart = entry->next;
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
inconsistency = true;
2020-03-22 21:19:43 +00:00
}
} else {
2020-03-17 04:31:30 +00:00
entry->prev->next = entry->next;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
2020-03-22 21:19:43 +00:00
if (!entry->next) {
if (entry == sStackInfoListEnd) {
2020-03-17 04:31:30 +00:00
sStackInfoListEnd = entry->prev;
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
inconsistency = true;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
}
2020-03-22 21:19:43 +00:00
if (inconsistency) {
2020-03-17 04:31:30 +00:00
osSyncPrintf(VT_COL(RED, WHITE) "stackcheck_cleanup: %08x リスト不整合です\n" VT_RST, entry);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
}
2020-03-22 21:19:43 +00:00
StackStatus StackCheck_GetState(StackEntry* entry) {
2020-03-17 04:31:30 +00:00
u32* last;
u32 used;
u32 free;
s32 ret;
2020-03-22 21:19:43 +00:00
for (last = (u32*)entry->head; (u32)last < entry->tail; last++) {
if (entry->initValue != *last) {
2020-03-17 04:31:30 +00:00
break;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
}
used = entry->tail - (u32)last;
free = (u32)last - entry->head;
2020-03-22 21:19:43 +00:00
if (free == 0) {
2020-03-17 04:31:30 +00:00
ret = STACK_STATUS_OVERFLOW;
osSyncPrintf(VT_FGCOL(RED));
} else if (free < (u32)entry->minSpace && entry->minSpace != -1) {
2020-03-17 04:31:30 +00:00
ret = STACK_STATUS_WARNING;
osSyncPrintf(VT_FGCOL(YELLOW));
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
osSyncPrintf(VT_FGCOL(GREEN));
ret = STACK_STATUS_OK;
}
2020-03-22 21:19:43 +00:00
osSyncPrintf("head=%08x tail=%08x last=%08x used=%08x free=%08x [%s]\n", entry->head, entry->tail, last, used, free,
Fix/cleanup/rephrase miscellaneous stuff (#983) * Add parens around params usage in VEC_SET macro * Remove unnecessary space character in a xml * Use defines instead of magic values in head/tail magic comments * Use `OS_USEC_TO_CYCLES` to make a time look better in `Graph_TaskSet00` * `0x25800` -> `sizeof(u16[SCREEN_HEIGHT][SCREEN_WIDTH])` * `0x803DA800` -> `0x80400000 - frame buffer size` * Use `OS_VI_` defines instead of hex * Add empty line after some variable declarations * Remove unused `extern CutsceneData` in `z_bg_dy_yoseizo.c` * `Matrix_MtxFToYXZRotS` does not use `MTXMODE_` * Use `MTXMODE_` more * Remove `ASCII_TO_U32`, use `'IS64'` * Add explicit `!= NULL` in some ternaries * Use `INV_CONTENT`, `AMMO` macros more * Use `PLAYER_AP_` enum more to compare to `Player#heldItemActionParam` * Get rid of lowercase hex (outside libultra) * `gWindMill*` -> `gWindmill*` * Format and small fix enums in `z_boss_mo.h` * Use `CHECK_BTN_ANY` more * Fix xz/xy mistake in comment in tektite * Rephrase comments mentioning "the devs" in a more neutral way * Clean-up some objectively useless parens * Fix some negative values written as u16 instead of s16 in ichains * `SKJ_ACTON_` -> `SKJ_ACTION_` * Run formatter * Fix unk_ offset of `TransformUpdateIndex#unk_10` -> `unk_0E` * Remove comments using in-game text * Remove `U` suffix from integer literals * Revert "Remove `ASCII_TO_U32`, use `'IS64'`" This reverts commit c801337dde9fe5e8b7a7ecf85ad3629bf5b87aaf. * Use `PLAYER_STR_*` to compare to `CUR_UPG_VALUE(UPG_STRENGTH)` * Add empty line after decl x2 * Revert "Use `PLAYER_STR_*` to compare to `CUR_UPG_VALUE(UPG_STRENGTH)`" This reverts commit d80bdb32da449edc74e02b8ab3f5a2c532e74bdb. * Make `CUR_UPG_VALUE(UPG_STRENGTH)` compare to integers (eventually needs its own enum) * Only use `PLAYER_SHIELD_` enum with `Player#currentShield` * Only use `PLAYER_TUNIC_` enum with `Player#currentTunic`
2021-10-03 03:17:09 +00:00
entry->name != NULL ? entry->name : "(null)");
2020-03-17 04:31:30 +00:00
osSyncPrintf(VT_RST);
2020-03-22 21:19:43 +00:00
if (ret != STACK_STATUS_OK) {
2020-03-17 04:31:30 +00:00
LogUtils_LogHexDump(entry->head, entry->tail - entry->head);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
return ret;
}
u32 StackCheck_CheckAll(void) {
2020-03-17 04:31:30 +00:00
u32 ret = 0;
StackEntry* iter = sStackInfoListStart;
2020-03-22 21:19:43 +00:00
while (iter) {
2020-03-17 04:31:30 +00:00
u32 state = StackCheck_GetState(iter);
2020-03-22 21:19:43 +00:00
if (state != STACK_STATUS_OK) {
2020-03-17 04:31:30 +00:00
ret = 1;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
iter = iter->next;
}
return ret;
}
2020-03-22 21:19:43 +00:00
u32 StackCheck_Check(StackEntry* entry) {
if (entry == NULL) {
2020-03-17 04:31:30 +00:00
return StackCheck_CheckAll();
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
return StackCheck_GetState(entry);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
}