mirror of
https://github.com/zeldaret/mm.git
synced 2026-09-13 04:35:16 -04:00
stackcheck.h (#1204)
* stackcheck.h * warning * Update src/boot_O2/stackcheck.c Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> * Update src/boot_O2/stackcheck.c Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> * Update src/boot_O2/stackcheck.c Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> * stack * format * bss * review * review --------- Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com>
This commit is contained in:
+30
-27
@@ -1,18 +1,19 @@
|
||||
#include "global.h"
|
||||
#include "stackcheck.h"
|
||||
#include "libc/stdbool.h"
|
||||
#include "libc/stdint.h"
|
||||
|
||||
StackEntry* sStackInfoListStart = NULL;
|
||||
StackEntry* sStackInfoListEnd = NULL;
|
||||
|
||||
void StackCheck_Init(StackEntry* entry, void* stackTop, void* stackBottom, u32 initValue, s32 minSpace,
|
||||
void StackCheck_Init(StackEntry* entry, void* stackBottom, void* stackTop, u32 initValue, s32 minSpace,
|
||||
const char* name) {
|
||||
StackEntry* iter;
|
||||
u32* addr;
|
||||
|
||||
if (!entry) {
|
||||
if (entry == NULL) {
|
||||
sStackInfoListStart = NULL;
|
||||
} else {
|
||||
entry->head = (u32)stackTop;
|
||||
entry->tail = (u32)stackBottom;
|
||||
StackEntry* iter;
|
||||
|
||||
entry->head = stackBottom;
|
||||
entry->tail = stackTop;
|
||||
entry->initValue = initValue;
|
||||
entry->minSpace = minSpace;
|
||||
entry->name = name;
|
||||
@@ -32,13 +33,14 @@ void StackCheck_Init(StackEntry* entry, void* stackTop, void* stackBottom, u32 i
|
||||
}
|
||||
|
||||
sStackInfoListEnd = entry;
|
||||
if (!sStackInfoListStart) {
|
||||
if (sStackInfoListStart == NULL) {
|
||||
sStackInfoListStart = entry;
|
||||
}
|
||||
|
||||
if (entry->minSpace != -1) {
|
||||
addr = (u32*)entry->head;
|
||||
while ((u32)addr < entry->tail) {
|
||||
u32* addr = entry->head;
|
||||
|
||||
while (addr < (u32*)entry->tail) {
|
||||
*addr++ = entry->initValue;
|
||||
}
|
||||
}
|
||||
@@ -46,13 +48,13 @@ void StackCheck_Init(StackEntry* entry, void* stackTop, void* stackBottom, u32 i
|
||||
}
|
||||
|
||||
void StackCheck_Cleanup(StackEntry* entry) {
|
||||
u32 inconsistency = 0; // unused variable needed to match
|
||||
u32 inconsistency = false;
|
||||
|
||||
if (!entry->prev) {
|
||||
if (entry->prev == NULL) {
|
||||
if (entry == sStackInfoListStart) {
|
||||
sStackInfoListStart = entry->next;
|
||||
} else {
|
||||
inconsistency = 1;
|
||||
inconsistency = true;
|
||||
}
|
||||
} else {
|
||||
entry->prev->next = entry->next;
|
||||
@@ -62,7 +64,7 @@ void StackCheck_Cleanup(StackEntry* entry) {
|
||||
if (entry == sStackInfoListEnd) {
|
||||
sStackInfoListEnd = entry->prev;
|
||||
} else {
|
||||
inconsistency = 1;
|
||||
inconsistency = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,22 +73,22 @@ void StackCheck_Cleanup(StackEntry* entry) {
|
||||
|
||||
StackStatus StackCheck_GetState(StackEntry* entry) {
|
||||
u32* last;
|
||||
u32 used;
|
||||
u32 free;
|
||||
s32 status;
|
||||
size_t used;
|
||||
size_t free;
|
||||
StackStatus status;
|
||||
|
||||
for (last = (u32*)entry->head; (u32)last < entry->tail; last++) {
|
||||
for (last = entry->head; last < (u32*)entry->tail; last++) {
|
||||
if (entry->initValue != *last) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
used = entry->tail - (u32)last;
|
||||
free = (u32)last - entry->head;
|
||||
used = (uintptr_t)entry->tail - (uintptr_t)last;
|
||||
free = (uintptr_t)last - (uintptr_t)entry->head;
|
||||
|
||||
if (free == 0) {
|
||||
status = STACK_STATUS_OVERFLOW;
|
||||
} else if (free < (u32)entry->minSpace && entry->minSpace != -1) {
|
||||
} else if ((free < (size_t)entry->minSpace) && (entry->minSpace != -1)) {
|
||||
status = STACK_STATUS_WARNING;
|
||||
} else {
|
||||
status = STACK_STATUS_OK;
|
||||
@@ -95,13 +97,14 @@ StackStatus StackCheck_GetState(StackEntry* entry) {
|
||||
return status;
|
||||
}
|
||||
|
||||
u32 StackCheck_CheckAll() {
|
||||
u32 StackCheck_CheckAll(void) {
|
||||
u32 ret = 0;
|
||||
StackEntry* iter = sStackInfoListStart;
|
||||
|
||||
while (iter) {
|
||||
u32 state = StackCheck_GetState(iter);
|
||||
if (state) {
|
||||
while (iter != NULL) {
|
||||
StackStatus state = StackCheck_GetState(iter);
|
||||
|
||||
if (state != STACK_STATUS_OK) {
|
||||
ret = 1;
|
||||
}
|
||||
iter = iter->next;
|
||||
@@ -111,7 +114,7 @@ u32 StackCheck_CheckAll() {
|
||||
}
|
||||
|
||||
u32 StackCheck_Check(StackEntry* entry) {
|
||||
if (!entry) {
|
||||
if (entry == NULL) {
|
||||
return StackCheck_CheckAll();
|
||||
} else {
|
||||
return StackCheck_GetState(entry);
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
#include "prevent_bss_reordering.h"
|
||||
#include "global.h"
|
||||
#include "stack.h"
|
||||
#include "stackcheck.h"
|
||||
|
||||
StackEntry sBootStackInfo;
|
||||
OSThread sIdleThread;
|
||||
STACK(sIdleThreadStack, 0x400);
|
||||
STACK(sIdleStack, 0x400);
|
||||
StackEntry sIdleStackInfo;
|
||||
STACK(sBootThreadStack, 0x400);
|
||||
STACK(sBootStack, 0x400);
|
||||
|
||||
void bootproc(void) {
|
||||
StackCheck_Init(&sBootStackInfo, sBootThreadStack, STACK_TOP(sBootThreadStack), 0, -1, "boot");
|
||||
StackCheck_Init(&sBootStackInfo, sBootStack, STACK_TOP(sBootStack), 0, -1, "boot");
|
||||
osMemSize = osGetMemSize();
|
||||
func_800818F4();
|
||||
osInitialize();
|
||||
osUnmapTLBAll();
|
||||
gCartHandle = osCartRomInit();
|
||||
StackCheck_Init(&sIdleStackInfo, sIdleThreadStack, STACK_TOP(sIdleThreadStack), 0, 0x100, "idle");
|
||||
osCreateThread(&sIdleThread, Z_THREAD_ID_IDLE, Idle_ThreadEntry, NULL, STACK_TOP(sIdleThreadStack),
|
||||
Z_PRIORITY_IDLE);
|
||||
StackCheck_Init(&sIdleStackInfo, sIdleStack, STACK_TOP(sIdleStack), 0, 0x100, "idle");
|
||||
osCreateThread(&sIdleThread, Z_THREAD_ID_IDLE, Idle_ThreadEntry, NULL, STACK_TOP(sIdleStack), Z_PRIORITY_IDLE);
|
||||
osStartThread(&sIdleThread);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "global.h"
|
||||
#include "stack.h"
|
||||
#include "vt.h"
|
||||
#include "stackcheck.h"
|
||||
|
||||
extern FaultThreadStruct* sFaultContext;
|
||||
extern f32 D_8009BE54;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "prevent_bss_reordering.h"
|
||||
#include "global.h"
|
||||
#include "stack.h"
|
||||
#include "buffers.h"
|
||||
#include "stackcheck.h"
|
||||
|
||||
u8 D_80096B20 = 1;
|
||||
vu8 gViConfigUseDefault = 1;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "global.h"
|
||||
#include "stackcheck.h"
|
||||
|
||||
vs32 gIrqMgrResetStatus = 0;
|
||||
volatile OSTime sIrqMgrResetTime = 0;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "prevent_bss_reordering.h"
|
||||
#include "global.h"
|
||||
#include "stack.h"
|
||||
#include "stackcheck.h"
|
||||
|
||||
u32 sDmaMgrDmaBuffSize = 0x2000;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "global.h"
|
||||
#include "slowly.h"
|
||||
#include "stack.h"
|
||||
#include "stackcheck.h"
|
||||
|
||||
/**
|
||||
* Assigns the "save" values in PreRender
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "global.h"
|
||||
#include "buffers.h"
|
||||
#include "stack.h"
|
||||
#include "stackcheck.h"
|
||||
|
||||
extern OSMesgQueue sSiIntMsgQ;
|
||||
extern OSMesg sSiIntMsgBuf[1];
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "prevent_bss_reordering.h"
|
||||
#include "global.h"
|
||||
#include "stackcheck.h"
|
||||
|
||||
#define RSP_DONE_MSG 667
|
||||
#define RDP_DONE_MSG 668
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "global.h"
|
||||
#include "stack.h"
|
||||
#include "stackcheck.h"
|
||||
#include "system_malloc.h"
|
||||
|
||||
// extern UNK_TYPE1 D_801FBE10;
|
||||
@@ -7,10 +8,10 @@
|
||||
// extern UNK_TYPE1 D_801FBE2C;
|
||||
// extern UNK_TYPE4 D_801FBE30;
|
||||
extern STACK(sSysFlashromStack, 0x1000);
|
||||
extern StackEntry sys_flashromStackEntry;
|
||||
extern OSThread sys_flashromOSThread;
|
||||
extern StackEntry sSysFlashromStackInfo;
|
||||
extern OSThread sSysFlashromThread;
|
||||
extern s80185D40 D_801FD008;
|
||||
extern OSMesg D_801FD034;
|
||||
extern OSMesg D_801FD034[1];
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/sys_flashrom/func_801857C0.s")
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
#include "slowly.h"
|
||||
#include "global.h"
|
||||
#include "stackcheck.h"
|
||||
|
||||
void Slowly_Main(SlowlyMgr* slowly) {
|
||||
slowly->status |= SLOWLY_STATUS_STARTED;
|
||||
|
||||
Reference in New Issue
Block a user