1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
#include "assert.h"
#include <revolution/os.h>
#include <revolution/base/PPCArch.h>
#include <revolution/vi.h>
#include "console.h"
#include "mapFile.h"
#include "directPrint.h"
#include "global.h"
namespace nw4hbm {
namespace db {
using namespace detail;
static OSAlarm sWarningAlarm;
static u32 sWarningTime;
static ConsoleHead* sAssertionConsole;
static bool sDispWarningAuto;
static void Assertion_Printf_(const char* fmt, ...) {
va_list vlist;
va_start(vlist, fmt);
if (sAssertionConsole) {
Console_VFPrintf(CONSOLE_OUTPUT_ALL, sAssertionConsole, fmt, vlist);
} else {
OSVReport(fmt, vlist);
}
va_end(vlist);
}
static bool ShowMapInfoSubroutine_(u32 address, u8 preCRFlag) {
u8 strBuf[260];
if (!MapFile_Exists()) {
return false;
}
if (address < 0x80000000 || address > 0x82FFFFFF) {
return false;
}
if (MapFile_QuerySymbol(address, strBuf, sizeof(strBuf))) {
Assertion_Printf_("%s\n", strBuf);
return true;
} else {
return false;
}
}
static void ShowStack_(u32 sp) NO_INLINE {
Assertion_Printf_("-------------------------------- TRACE\n");
Assertion_Printf_("Address: BackChain LR save\n");
u32* p = (u32*)sp;
for (u32 i = 0; i < 16; i++, p = (u32*)*p) {
if (p == NULL || p == (u32*)0xFFFFFFFF || !((u32)p & 0x80000000))
break;
Assertion_Printf_("%08X: %08X %08X ", p, p[0], p[1]);
if (!ShowMapInfoSubroutine_(p[1], false)) {
Assertion_Printf_("\n");
}
}
}
DECL_WEAK void VPanic(const char* file, int line, const char* fmt, std::va_list vlist) {
register u32 stackPointer;
asm {
lwz stackPointer, 0(r1)
}
OSDisableInterrupts();
VISetPreRetraceCallback(NULL);
VISetPostRetraceCallback(NULL);
if (sAssertionConsole) {
detail::DirectPrint_SetupFB(NULL);
}
ShowStack_(stackPointer);
if (sAssertionConsole != NULL) {
Console_Printf(sAssertionConsole, "%s:%d Panic:", file, line);
Console_VFPrintf(CONSOLE_OUTPUT_ALL, sAssertionConsole, fmt, vlist);
Console_Printf(sAssertionConsole, "\n");
Console_ShowLatestLine(sAssertionConsole);
Console_SetVisible(sAssertionConsole, true);
Console_DrawDirect(sAssertionConsole);
} else {
OSReport("%s:%d Panic:", file, line);
OSVReport(fmt, vlist);
OSReport("\n");
}
PPCHalt();
}
DECL_WEAK void detail::Panic(const char* file, int line, const char* fmt, ...) {
va_list vlist;
va_start(vlist, fmt);
VPanic(file, line, fmt, vlist);
}
static OSAlarm& GetWarningAlarm_();
static void WarningAlarmFunc_(OSAlarm* alarm, OSContext* context);
DECL_WEAK void VWarning(const char* file, int line, const char* fmt, std::va_list vlist) {
if (sAssertionConsole != NULL) {
Console_Printf(sAssertionConsole, "%s:%d Warning:", file, line);
Console_VFPrintf(CONSOLE_OUTPUT_ALL, sAssertionConsole, fmt, vlist);
Console_Printf(sAssertionConsole, "\n");
Console_ShowLatestLine(sAssertionConsole);
Console_SetVisible(sAssertionConsole, true);
} else {
OSReport("%s:%d Warning:", file, line);
OSVReport(fmt, vlist);
OSReport("\n");
}
}
DECL_WEAK void detail::Warning(const char* file, int line, const char* fmt, ...) {
OSAlarm& alarm = GetWarningAlarm_();
va_list vlist;
va_start(vlist, fmt);
VWarning(file, line, fmt, vlist);
va_end(vlist);
if (sWarningTime > 0) {
OSCancelAlarm(&sWarningAlarm);
OSSetAlarm(&sWarningAlarm, sWarningTime, WarningAlarmFunc_);
}
}
namespace detail {
void Log(const char* fmt, ...) {
va_list vlist;
}
} // namespace detail
ConsoleHead* Assertion_SetConsole(ConsoleHead* console) {
ConsoleHead* before = sAssertionConsole;
sAssertionConsole = console;
return before;
}
ConsoleHead* Assertion_GetConsole() {
return sAssertionConsole;
}
void Assertion_ShowConsole(u32 time) {
if (sAssertionConsole != NULL) {
OSAlarm& alarm = GetWarningAlarm_();
OSCancelAlarm(&alarm);
Console_SetVisible(sAssertionConsole, true);
if (time != 0) {
OSSetAlarm(&alarm, time, WarningAlarmFunc_);
}
}
}
void Assertion_HideConsole() {
// OSAlarm& alarm;
}
void Assertion_SetWarningTime(u32 time) {}
static OSAlarm& GetWarningAlarm_() {
static bool sInitializedAlarm;
if (!sInitializedAlarm) {
OSCreateAlarm(&sWarningAlarm);
sInitializedAlarm = true;
}
return sWarningAlarm;
}
static void WarningAlarmFunc_(OSAlarm* alarm, OSContext* context) {
Console_SetVisible(sAssertionConsole, false);
}
} // namespace db
} // namespace nw4r
|