1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-14 05:19:36 +00:00
oot/src/boot/stackcheck.c
Dragorn421 f1d27bf653
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 c801337dde.

* 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 d80bdb32da.

* 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-02 23:17:09 -04:00

133 lines
3.3 KiB
C

#include "global.h"
#include "vt.h"
StackEntry* sStackInfoListStart = NULL;
StackEntry* sStackInfoListEnd = NULL;
void StackCheck_Init(StackEntry* entry, void* stackTop, void* stackBottom, u32 initValue, s32 minSpace,
const char* name) {
StackEntry* iter;
u32* addr;
if (entry == NULL) {
sStackInfoListStart = NULL;
} else {
entry->head = (u32)stackTop;
entry->tail = (u32)stackBottom;
entry->initValue = initValue;
entry->minSpace = minSpace;
entry->name = name;
iter = sStackInfoListStart;
while (iter) {
if (iter == entry) {
osSyncPrintf(VT_COL(RED, WHITE) "stackcheck_init: %08x は既にリスト中にある\n" VT_RST, entry);
return;
}
iter = iter->next;
}
entry->prev = sStackInfoListEnd;
entry->next = NULL;
if (sStackInfoListEnd) {
sStackInfoListEnd->next = entry;
}
sStackInfoListEnd = entry;
if (!sStackInfoListStart) {
sStackInfoListStart = entry;
}
if (entry->minSpace != -1) {
addr = (u32*)entry->head;
while ((u32)addr < entry->tail) {
*addr++ = entry->initValue;
}
}
}
}
void StackCheck_Cleanup(StackEntry* entry) {
bool inconsistency = false;
if (!entry->prev) {
if (entry == sStackInfoListStart) {
sStackInfoListStart = entry->next;
} else {
inconsistency = true;
}
} else {
entry->prev->next = entry->next;
}
if (!entry->next) {
if (entry == sStackInfoListEnd) {
sStackInfoListEnd = entry->prev;
} else {
inconsistency = true;
}
}
if (inconsistency) {
osSyncPrintf(VT_COL(RED, WHITE) "stackcheck_cleanup: %08x リスト不整合です\n" VT_RST, entry);
}
}
StackStatus StackCheck_GetState(StackEntry* entry) {
u32* last;
u32 used;
u32 free;
s32 ret;
for (last = (u32*)entry->head; (u32)last < entry->tail; last++) {
if (entry->initValue != *last) {
break;
}
}
used = entry->tail - (u32)last;
free = (u32)last - entry->head;
if (free == 0) {
ret = STACK_STATUS_OVERFLOW;
osSyncPrintf(VT_FGCOL(RED));
} else if (free < (u32)entry->minSpace && entry->minSpace != -1) {
ret = STACK_STATUS_WARNING;
osSyncPrintf(VT_FGCOL(YELLOW));
} else {
osSyncPrintf(VT_FGCOL(GREEN));
ret = STACK_STATUS_OK;
}
osSyncPrintf("head=%08x tail=%08x last=%08x used=%08x free=%08x [%s]\n", entry->head, entry->tail, last, used, free,
entry->name != NULL ? entry->name : "(null)");
osSyncPrintf(VT_RST);
if (ret != STACK_STATUS_OK) {
LogUtils_LogHexDump(entry->head, entry->tail - entry->head);
}
return ret;
}
u32 StackCheck_CheckAll(void) {
u32 ret = 0;
StackEntry* iter = sStackInfoListStart;
while (iter) {
u32 state = StackCheck_GetState(iter);
if (state != STACK_STATUS_OK) {
ret = 1;
}
iter = iter->next;
}
return ret;
}
u32 StackCheck_Check(StackEntry* entry) {
if (entry == NULL) {
return StackCheck_CheckAll();
} else {
return StackCheck_GetState(entry);
}
}