replace ad hoc driver loading with a proper driver manager, new DDK, new PnP manager with device matching, asynchronous startup, resource ownership and removal, add shared PCI capability helpers, replace typed, rigid services with a proper service manager, implement proper system shutdown and restart, shutting down unloads drivers and shuts down services, add simple power button, remove heavyweight boot self-tests and SMP stress runs, add monotonic timestamps to kernel debug output, fruitless USB and PS/2 fixes, make test builds opt in.
This commit is contained in:
1 parent
c0ad63c27f
commit
d36f19509c
160 files changed
+6563
-7366
No files matched your search
+65
-10
@@ -38,6 +38,10 @@ static size_t gDebugLogSize;
|
||||
static size_t gDebugLogWrite;
|
||||
static size_t gDebugLogUsed;
|
||||
static volatile int32_t gDebugLogFlushing;
|
||||
static bool gDebugAtLineStart = true;
|
||||
static bool gDebugClockReady;
|
||||
static uint64_t gDebugClockOrigin;
|
||||
static uint64_t gDebugLastTick;
|
||||
|
||||
// Appends bytes to the in-memory debug log while its lock is held.
|
||||
static void KiDebugLogAppendLocked(const char* text, size_t len) {
|
||||
@@ -185,6 +189,30 @@ uint32_t KeGetDebugFlags(void) {
|
||||
return gDebugFlags;
|
||||
}
|
||||
|
||||
// Prefixes each logical debug line with elapsed monotonic seconds when available.
|
||||
static size_t KiDebugTimestamp(char* buffer, size_t capacity) {
|
||||
if (!gDebugHal || !gDebugHal->Timer.QueryTicks)
|
||||
return 0;
|
||||
|
||||
uint64_t tick = gDebugHal->Timer.QueryTicks();
|
||||
if (tick == 0)
|
||||
return 0;
|
||||
if (!gDebugClockReady) {
|
||||
gDebugClockOrigin = tick;
|
||||
gDebugLastTick = tick;
|
||||
gDebugClockReady = true;
|
||||
}
|
||||
if (tick < gDebugLastTick)
|
||||
tick = gDebugLastTick;
|
||||
gDebugLastTick = tick;
|
||||
|
||||
uint64_t elapsed = tick - gDebugClockOrigin;
|
||||
int count = snprintf_(buffer, capacity, "[%6llu.%06llu] ",
|
||||
(unsigned long long)(elapsed / 1000000ull),
|
||||
(unsigned long long)(elapsed % 1000000ull));
|
||||
return count > 0 && (size_t)count < capacity ? (size_t)count : 0;
|
||||
}
|
||||
|
||||
// Writes one formatted kernel diagnostic.
|
||||
__declspec(dllexport) void DbgPrint(const char* fmt, ...) {
|
||||
if (!gDebugEnabled || !fmt)
|
||||
@@ -202,23 +230,50 @@ __declspec(dllexport) void DbgPrint(const char* fmt, ...) {
|
||||
if (length >= sizeof(line))
|
||||
length = sizeof(line) - 1u;
|
||||
}
|
||||
if (length == 0)
|
||||
return;
|
||||
|
||||
bool panic = KiPanicIsActive();
|
||||
if (panic && !KiPanicCurrentCpuOwnsReport())
|
||||
KiPanicSecondaryHalt();
|
||||
|
||||
if (!panic) {
|
||||
uintptr_t lockFlags = KeAcquireSpinlock(&gDebugPrintLock);
|
||||
if (!NtlAtomicLoad32(&gDebugLogFlushing))
|
||||
KiDebugLogAppendLocked(line, length);
|
||||
KeReleaseSpinlock(&gDebugPrintLock, lockFlags);
|
||||
uint32_t stream = panic ? HAL_OUTPUT_STREAM_PANIC : HAL_OUTPUT_STREAM_DEBUG;
|
||||
uint32_t flags = panic ? HAL_OUTPUT_WRITE_EMERGENCY : 0;
|
||||
uint32_t foreground = panic ? 0x00FF2222u : 0x00CCCCCCu;
|
||||
uint32_t background = panic ? 0x00000000u : 0x00012456u;
|
||||
|
||||
uintptr_t lockFlags = 0;
|
||||
if (!panic)
|
||||
lockFlags = KeAcquireSpinlock(&gDebugPrintLock);
|
||||
|
||||
size_t offset = 0;
|
||||
while (offset < length) {
|
||||
size_t end = offset;
|
||||
while (end < length && line[end] != '\n')
|
||||
end++;
|
||||
if (end < length)
|
||||
end++;
|
||||
|
||||
if (panic || gDebugAtLineStart) {
|
||||
char prefix[48];
|
||||
size_t prefixLength = KiDebugTimestamp(prefix, sizeof(prefix));
|
||||
if (prefixLength) {
|
||||
if (!panic && !NtlAtomicLoad32(&gDebugLogFlushing))
|
||||
KiDebugLogAppendLocked(prefix, prefixLength);
|
||||
KiOutputWrite(stream, flags, foreground, background, prefix, prefixLength);
|
||||
}
|
||||
}
|
||||
|
||||
if (!panic && !NtlAtomicLoad32(&gDebugLogFlushing))
|
||||
KiDebugLogAppendLocked(line + offset, end - offset);
|
||||
KiOutputWrite(stream, flags, foreground, background, line + offset, end - offset);
|
||||
if (!panic)
|
||||
gDebugAtLineStart = line[end - 1u] == '\n';
|
||||
offset = end;
|
||||
}
|
||||
|
||||
KiOutputWrite(panic ? HAL_OUTPUT_STREAM_PANIC : HAL_OUTPUT_STREAM_DEBUG,
|
||||
panic ? HAL_OUTPUT_WRITE_EMERGENCY : 0,
|
||||
panic ? 0x00FF2222u : 0x00CCCCCCu,
|
||||
panic ? 0x00000000u : 0x00012456u,
|
||||
line, length);
|
||||
if (!panic)
|
||||
KeReleaseSpinlock(&gDebugPrintLock, lockFlags);
|
||||
}
|
||||
|
||||
// Writes one debug-log segment and rejects successful zero-progress writes.
|
||||
|
||||
Reference in new issue
Block a user