rename dependency files folder; put full log in kernel panic report

This commit is contained in:
nakst 2021-12-29 09:47:34 +00:00
parent e26fb975e6
commit 510d4d866f
11 changed files with 171 additions and 38 deletions

View File

@ -153,6 +153,8 @@ void ProcessorOut8Delayed(uint16_t port, uint8_t value) {
ProcessorOut8(port, value);
// Read an unused port to get a short delay.
// TODO This might hang some old laptops after ACPI is enabled.
// See https://lwn.net/Articles/263418/
ProcessorIn8(IO_UNUSED_DELAY);
}

View File

@ -25,6 +25,13 @@ void BGADebugPutBlock(uintptr_t x, uintptr_t y, bool toggle) {
((KPCIDevice *) vboxDisplay->parent)->baseAddressesVirtual[0]);
}
int BGADebugPutData(const uint8_t *data, size_t dataBytes) {
return GraphicsDebugPutData32(data, dataBytes,
vboxDisplay->screenWidth, vboxDisplay->screenHeight,
vboxDisplay->screenWidth * 4,
((KPCIDevice *) vboxDisplay->parent)->baseAddressesVirtual[0]);
}
void BGADebugClearScreen() {
GraphicsDebugClearScreen32(vboxDisplay->screenWidth, vboxDisplay->screenHeight,
vboxDisplay->screenWidth * 4,
@ -67,6 +74,7 @@ void BGADeviceAttached(KDevice *_parent) {
// Setup the graphics target.
device->updateScreen = BGAUpdateScreen;
device->debugPutBlock = BGADebugPutBlock;
device->debugPutData = BGADebugPutData;
device->debugClearScreen = BGADebugClearScreen;
ProcessorOut16(IO_BGA_INDEX, 1 /* x resolution */);
device->screenWidth = ProcessorIn16(IO_BGA_DATA);

View File

@ -591,6 +591,35 @@ void GraphicsDebugPutBlock32(uintptr_t x, uintptr_t y, bool toggle,
linearBuffer[(y + 1) * stride + (x + 1) * 4 + 2] = 0;
}
int GraphicsDebugPutData32(const uint8_t *data, size_t dataBytes,
unsigned screenWidth, unsigned screenHeight, unsigned stride, volatile uint8_t *linearBuffer) {
uintptr_t width = (dataBytes + screenHeight * 2 - 1) / (screenHeight * 2);
uintptr_t x = screenWidth - width, y = 0;
for (uintptr_t i = 0; i < dataBytes; i += 2) {
linearBuffer[y * stride + x * 4 + 0] = data[i];
linearBuffer[y * stride + x * 4 + 1] = data[i + 1];
// Leave the red channel unmodified so we can see through to the crashed desktop state.
if (++x == screenWidth) x -= width, y++;
}
// Detection pattern.
linearBuffer[0 * stride + (screenWidth - width + 0) * 4 + 2] = 0x12;
linearBuffer[0 * stride + (screenWidth - width + 1) * 4 + 2] = 0x34;
linearBuffer[0 * stride + (screenWidth - width + 2) * 4 + 2] = 0x56;
linearBuffer[0 * stride + (screenWidth - width + 3) * 4 + 2] = 0x78;
linearBuffer[0 * stride + (screenWidth - 1 - 0) * 4 + 2] = 0x12;
linearBuffer[0 * stride + (screenWidth - 1 - 1) * 4 + 2] = 0x34;
linearBuffer[0 * stride + (screenWidth - 1 - 2) * 4 + 2] = 0x56;
linearBuffer[0 * stride + (screenWidth - 1 - 3) * 4 + 2] = 0x78;
linearBuffer[(screenHeight - 1) * stride + (screenWidth - 1 - 0) * 4 + 2] = 0x12;
linearBuffer[(screenHeight - 1) * stride + (screenWidth - 1 - 1) * 4 + 2] = 0x34;
linearBuffer[(screenHeight - 1) * stride + (screenWidth - 1 - 2) * 4 + 2] = 0x56;
linearBuffer[(screenHeight - 1) * stride + (screenWidth - 1 - 3) * 4 + 2] = 0x78;
return width;
}
void GraphicsDebugClearScreen32(unsigned screenWidth, unsigned screenHeight, unsigned stride, volatile uint8_t *linearBuffer) {
for (uintptr_t i = 0; i < screenHeight; i++) {
for (uintptr_t j = 0; j < screenWidth * 4; j += 4) {

View File

@ -25,6 +25,7 @@ void KernelMain(uintptr_t) {
desktopProcess = ProcessSpawn(PROCESS_DESKTOP); // Spawn the desktop process.
DriversInitialise(); // Load the root device.
ProcessStart(desktopProcess, EsLiteral(K_DESKTOP_EXECUTABLE)); // Start the desktop process.
KernelPanic("Test\n");
KEventWait(&shutdownEvent, ES_WAIT_NO_TIMEOUT); // Wait for a shutdown request.
ProcessTerminateAll(); // Terminate all user processes.
FSShutdown(); // Flush file cache and unmount filesystems.

View File

@ -923,6 +923,7 @@ struct KGraphicsTarget : KDevice {
void (*updateScreen)(K_USER_BUFFER const uint8_t *source, uint32_t sourceWidth, uint32_t sourceHeight, uint32_t sourceStride,
uint32_t destinationX, uint32_t destinationY);
void (*debugPutBlock)(uintptr_t x, uintptr_t y, bool toggle);
int (*debugPutData)(const uint8_t *data, size_t dataBytes); // Return the width used. dataBytes must be a multiple of 16.
void (*debugClearScreen)();
};
@ -939,6 +940,8 @@ void GraphicsUpdateScreen24(K_USER_BUFFER const uint8_t *_source, uint32_t sourc
uint32_t width, uint32_t height, uint32_t stride, volatile uint8_t *pixel);
void GraphicsDebugPutBlock32(uintptr_t x, uintptr_t y, bool toggle,
unsigned screenWidth, unsigned screenHeight, unsigned stride, volatile uint8_t *linearBuffer);
int GraphicsDebugPutData32(const uint8_t *data, size_t dataBytes,
unsigned screenWidth, unsigned screenHeight, unsigned stride, volatile uint8_t *linearBuffer);
void GraphicsDebugClearScreen32(unsigned screenWidth, unsigned screenHeight, unsigned stride, volatile uint8_t *linearBuffer);
// ---------------------------------------------------------------------------------------------------------------

View File

@ -138,11 +138,18 @@ void DebugWriteCharacter(uintptr_t character) {
void StartDebugOutput() {
if (graphics.target && graphics.target->debugClearScreen && graphics.target->debugPutBlock && !printToDebugger) {
graphics.target->debugClearScreen();
int widthUsed = 0;
if (graphics.target->debugPutData) {
widthUsed = graphics.target->debugPutData((const uint8_t *) kernelLog, KERNEL_LOG_SIZE);
}
debugRows = (graphics.height - 1) / VGA_FONT_HEIGHT;
debugColumns = (graphics.width - 1) / VGA_FONT_WIDTH - 2;
debugColumns = (graphics.width - 1 - widthUsed) / VGA_FONT_WIDTH - 2;
debugCurrentRow = debugCurrentColumn = 0;
printToDebugger = true;
graphics.target->debugClearScreen();
}
}
@ -203,7 +210,7 @@ void KernelPanic(const char *format, ...) {
StartDebugOutput();
EsPrint("\n--- System Error ---\n>> ");
EsPrint("\n--- System Error ---\n* If you are using an emulator, please capture a screenshot of the entire window and report the error. *\n>> ");
va_list arguments;
va_start(arguments, format);
@ -227,7 +234,8 @@ void KernelPanic(const char *format, ...) {
#ifdef ES_ARCH_X86_64
EsPrint("%z %d %x @%x:%x ", (GetCurrentThread() == thread) ? "=>" : " ",
thread->id, thread, thread->interruptContext->rip, thread->interruptContext->rbp);
thread->id, thread, thread->interruptContext ? thread->interruptContext->rip : 0,
thread->interruptContext ? thread->interruptContext->rbp : 0);
#endif
if (thread->state == THREAD_WAITING_EVENT) {
@ -248,7 +256,7 @@ void KernelPanic(const char *format, ...) {
for (uintptr_t i = 0; i < KGetCPUCount(); i++) {
CPULocalStorage *local = KGetCPULocal(i);
if (local->panicContext) {
if (local && local->panicContext) {
#ifdef ES_ARCH_X86_64
EsPrint("CPU %d LS %x RIP/RBP %x:%x TID %d\n", local->processorID, local,
local->panicContext->rip, local->panicContext->rbp,
@ -401,6 +409,8 @@ void KernelPanic(const char *format, ...) {
while (KWaitKey() != ES_SCANCODE_ENTER);
}
}
#else
EsPrint("End of report.\n");
#endif
ProcessorHalt();

View File

@ -4,7 +4,7 @@
cd "$(dirname "$0")"
# Create the bin directories.
mkdir -p bin bin/Dependency\ Files bin/Logs bin/generated_code bin/cache
mkdir -p bin bin/dependency_files bin/Logs bin/generated_code bin/cache
# Check that we are running on a sensible platform.
uname -o | grep Cygwin > /dev/null

View File

@ -149,7 +149,7 @@ int CallSystemF(const char *format, ...) {
void BuildAPIDependencies() {
if (CheckDependencies("API Header")) {
CallSystem("bin/build_core headers");
ParseDependencies("bin/Dependency Files/api_header.d", "API Header", false);
ParseDependencies("bin/dependency_files/api_header.d", "API Header", false);
}
CallSystem("ports/musl/build.sh " TARGET_NAME);
@ -366,8 +366,8 @@ void BuildUtilities() {
#define BUILD_UTILITY(x, y, z) \
if (CheckDependencies("Utilities." x)) { \
if (!CallSystem("gcc -MMD -MF \"bin/Dependency Files/" x ".d\" " "util/" z x ".c -o bin/" x " -g " WARNING_FLAGS " " y)) { \
ParseDependencies("bin/Dependency Files/" x ".d", "Utilities." x, false); \
if (!CallSystem("gcc -MMD -MF \"bin/dependency_files/" x ".d\" " "util/" z x ".c -o bin/" x " -g " WARNING_FLAGS " " y)) { \
ParseDependencies("bin/dependency_files/" x ".d", "Utilities." x, false); \
} \
}
@ -1233,9 +1233,9 @@ void DoCommand(const char *l) {
}
} else if (0 == strcmp(l, "designer2")) {
if (CheckDependencies("Utilities.Designer")) {
if (!CallSystem("g++ -MMD -MF \"bin/Dependency Files/designer2.d\" -D UI_LINUX -O3 "
if (!CallSystem("g++ -MMD -MF \"bin/dependency_files/designer2.d\" -D UI_LINUX -O3 "
"util/designer2.cpp -o bin/designer2 -g -lX11 -Wno-unused-parameter " WARNING_FLAGS)) {
ParseDependencies("bin/Dependency Files/designer2.d", "Utilities.Designer", false);
ParseDependencies("bin/dependency_files/designer2.d", "Utilities.Designer", false);
}
}

View File

@ -567,10 +567,10 @@ void BuildDesktop(Application *application) {
char buffer[4096];
snprintf(buffer, sizeof(buffer), "arch/%s/api.s", target);
ExecuteForApp(application, toolchainNasm, buffer, "-MD", "bin/Dependency Files/api1.d", "-o", "bin/Object Files/api1.o", ArgString(commonAssemblyFlags));
ExecuteForApp(application, toolchainCXX, "-MD", "-MF", "bin/Dependency Files/api2.d", "-c", "desktop/api.cpp", "-o", "bin/Object Files/api2.o",
ExecuteForApp(application, toolchainNasm, buffer, "-MD", "bin/dependency_files/api1.d", "-o", "bin/Object Files/api1.o", ArgString(commonAssemblyFlags));
ExecuteForApp(application, toolchainCXX, "-MD", "-MF", "bin/dependency_files/api2.d", "-c", "desktop/api.cpp", "-o", "bin/Object Files/api2.o",
ArgString(commonCompileFlags), ArgString(desktopProfilingFlags));
ExecuteForApp(application, toolchainCXX, "-MD", "-MF", "bin/Dependency Files/api3.d", "-c", "desktop/posix.cpp", "-o", "bin/Object Files/api3.o",
ExecuteForApp(application, toolchainCXX, "-MD", "-MF", "bin/dependency_files/api3.d", "-c", "desktop/posix.cpp", "-o", "bin/Object Files/api3.o",
ArgString(commonCompileFlags));
ExecuteForApp(application, toolchainCC, "-o", "bin/Desktop", "bin/Object Files/crti.o", "bin/Object Files/crtbegin.o",
"bin/Object Files/api1.o", "bin/Object Files/api2.o", "bin/Object Files/api3.o", "bin/Object Files/crtend.o", "bin/Object Files/crtn.o",
@ -650,7 +650,7 @@ void BuildApplication(Application *application) {
char objectFile[256], dependencyFile[256];
snprintf(objectFile, sizeof(objectFile), "bin/Object Files/%s_%d.o", application->name, (int) i);
snprintf(dependencyFile, sizeof(dependencyFile), "bin/Dependency Files/%s_%d.d", application->name, (int) i);
snprintf(dependencyFile, sizeof(dependencyFile), "bin/dependency_files/%s_%d.d", application->name, (int) i);
objectFilesPosition += sprintf(objectFiles + objectFilesPosition, "\"%s\" ", objectFile);
bool isC = sourceBytes > 2 && source[sourceBytes - 1] == 'c' && source[sourceBytes - 2] == '.';
@ -793,7 +793,7 @@ void ParseApplicationManifest(const char *manifestPath) {
for (uintptr_t i = 0; i < arrlenu(application.sources); i++) {
DependencyFile dependencyFile = {};
dependencyFile.name = application.name;
snprintf(dependencyFile.path, sizeof(dependencyFile.path), "bin/Dependency Files/%s_%d.d", application.name, (int) i);
snprintf(dependencyFile.path, sizeof(dependencyFile.path), "bin/dependency_files/%s_%d.d", application.name, (int) i);
arrput(application.dependencyFiles, dependencyFile);
}
@ -903,7 +903,7 @@ void OutputSystemConfiguration() {
void BuildModule(Application *application) {
char output[256], dependencyFile[256];
snprintf(output, sizeof(output), "bin/Object Files/%s.ekm", application->name);
snprintf(dependencyFile, sizeof(dependencyFile), "bin/Dependency Files/%s.d", application->name);
snprintf(dependencyFile, sizeof(dependencyFile), "bin/dependency_files/%s.d", application->name);
assert(arrlenu(application->sources) == 1);
ExecuteForApp(application, toolchainCXX, "-MD", "-MF", dependencyFile, "-c", application->sources[0], "-o",
@ -1021,11 +1021,11 @@ void ParseKernelConfiguration() {
FilePrintFormat(f, "#endif");
FileClose(f);
f = FileOpen("bin/Dependency Files/system_config.d", 'w');
f = FileOpen("bin/dependency_files/system_config.d", 'w');
FilePrintFormat(f, ": kernel/config.ini\n");
FileClose(f);
ParseDependencies("bin/Dependency Files/system_config.d", "Kernel Config", false);
DeleteFile("bin/Dependency Files/system_config.d");
ParseDependencies("bin/dependency_files/system_config.d", "Kernel Config", false);
DeleteFile("bin/dependency_files/system_config.d");
}
void LinkKernel() {
@ -1082,22 +1082,22 @@ void LinkKernel() {
void BuildKernel(Application *application) {
char buffer[4096];
snprintf(buffer, sizeof(buffer), "arch/%s/kernel.s", target);
ExecuteForApp(application, toolchainNasm, "-MD", "bin/Dependency Files/kernel2.d", buffer, "-o", "bin/Object Files/kernel_arch.o", ArgString(commonAssemblyFlags));
ExecuteForApp(application, toolchainNasm, "-MD", "bin/dependency_files/kernel2.d", buffer, "-o", "bin/Object Files/kernel_arch.o", ArgString(commonAssemblyFlags));
snprintf(buffer, sizeof(buffer), "-DARCH_KERNEL_SOURCE=<arch/%s/kernel.cpp>", target);
ExecuteForApp(application, toolchainCXX, "-MD", "-MF", "bin/Dependency Files/kernel.d", "-c", "kernel/main.cpp", "-o", "bin/Object Files/kernel.o",
ExecuteForApp(application, toolchainCXX, "-MD", "-MF", "bin/dependency_files/kernel.d", "-c", "kernel/main.cpp", "-o", "bin/Object Files/kernel.o",
ArgString(kernelCompileFlags), ArgString(cppCompileFlags), ArgString(commonCompileFlags), buffer);
if (application->error) __sync_fetch_and_or(&encounteredErrorsInKernelModules, 1);
}
void BuildBootloader(Application *application) {
ExecuteForApp(application, toolchainNasm, "-MD", "bin/Dependency Files/boot1.d", "-fbin",
ExecuteForApp(application, toolchainNasm, "-MD", "bin/dependency_files/boot1.d", "-fbin",
forEmulator ? "boot/x86/mbr.s" : "boot/x86/mbr-emu.s" , "-obin/mbr");
ExecuteForApp(application, toolchainNasm, "-MD", "bin/Dependency Files/boot2.d", "-fbin",
ExecuteForApp(application, toolchainNasm, "-MD", "bin/dependency_files/boot2.d", "-fbin",
"boot/x86/esfs-stage1.s", "-obin/stage1");
ExecuteForApp(application, toolchainNasm, "-MD", "bin/Dependency Files/boot3.d", "-fbin",
ExecuteForApp(application, toolchainNasm, "-MD", "bin/dependency_files/boot3.d", "-fbin",
"boot/x86/loader.s", "-obin/stage2",
"-Pboot/x86/esfs-stage2.s", (forEmulator && !bootUseVBE) ? "" : "-D BOOT_USE_VBE");
ExecuteForApp(application, toolchainNasm, "-MD", "bin/Dependency Files/boot4.d", "-fbin",
ExecuteForApp(application, toolchainNasm, "-MD", "bin/dependency_files/boot4.d", "-fbin",
"boot/x86/uefi_loader.s", "-obin/uefi_loader");
}
@ -1417,7 +1417,7 @@ int main(int argc, char **argv) {
if (driverSource && *driverSource) {
DependencyFile dependencyFile = {};
dependencyFile.name = driverName;
snprintf(dependencyFile.path, sizeof(dependencyFile.path), "bin/Dependency Files/%s.d", driverName);
snprintf(dependencyFile.path, sizeof(dependencyFile.path), "bin/dependency_files/%s.d", driverName);
Application application = {};
arrput(application.sources, driverSource);
@ -1474,7 +1474,7 @@ int main(int argc, char **argv) {
}
MakeDirectory("bin");
MakeDirectory("bin/Dependency Files");
MakeDirectory("bin/dependency_files");
MakeDirectory("bin/Object Files");
MakeDirectory("bin/Stripped Executables");
MakeDirectory("bin/generated_code");
@ -1541,10 +1541,10 @@ int main(int argc, char **argv) {
Application application = {};
application.name = "Bootloader";
application.buildCallback = BuildBootloader;
ADD_DEPENDENCY_FILE(application, "bin/Dependency Files/boot1.d", "Boot1");
ADD_DEPENDENCY_FILE(application, "bin/Dependency Files/boot2.d", "Boot2");
ADD_DEPENDENCY_FILE(application, "bin/Dependency Files/boot3.d", "Boot3");
ADD_DEPENDENCY_FILE(application, "bin/Dependency Files/boot4.d", "Boot4");
ADD_DEPENDENCY_FILE(application, "bin/dependency_files/boot1.d", "Boot1");
ADD_DEPENDENCY_FILE(application, "bin/dependency_files/boot2.d", "Boot2");
ADD_DEPENDENCY_FILE(application, "bin/dependency_files/boot3.d", "Boot3");
ADD_DEPENDENCY_FILE(application, "bin/dependency_files/boot4.d", "Boot4");
arrput(applications, application);
}
@ -1552,9 +1552,9 @@ int main(int argc, char **argv) {
Application application = {};
application.name = "Desktop";
application.buildCallback = BuildDesktop;
ADD_DEPENDENCY_FILE(application, "bin/Dependency Files/api1.d", "API1");
ADD_DEPENDENCY_FILE(application, "bin/Dependency Files/api2.d", "API2");
ADD_DEPENDENCY_FILE(application, "bin/Dependency Files/api3.d", "API3");
ADD_DEPENDENCY_FILE(application, "bin/dependency_files/api1.d", "API1");
ADD_DEPENDENCY_FILE(application, "bin/dependency_files/api2.d", "API2");
ADD_DEPENDENCY_FILE(application, "bin/dependency_files/api3.d", "API3");
arrput(applications, application);
}
@ -1568,8 +1568,8 @@ int main(int argc, char **argv) {
Application application = {};
application.name = "Kernel";
application.buildCallback = BuildKernel;
ADD_DEPENDENCY_FILE(application, "bin/Dependency Files/kernel.d", "Kernel1");
ADD_DEPENDENCY_FILE(application, "bin/Dependency Files/kernel2.d", "Kernel2");
ADD_DEPENDENCY_FILE(application, "bin/dependency_files/kernel.d", "Kernel1");
ADD_DEPENDENCY_FILE(application, "bin/dependency_files/kernel2.d", "Kernel2");
arrput(applications, application);
}

80
util/extract_log.c Normal file
View File

@ -0,0 +1,80 @@
#include <stdint.h>
#include <string.h>
#define EsCRTmemcpy memcpy
#define EsCRTmemset memset
#define EsCRTabs abs
#define STB_IMAGE_IMPLEMENTATION
#include "../shared/stb_image.h"
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: %s <path>\n", argv[0]);
exit(1);
}
int width, height, channels;
uint32_t *data = (uint32_t *) stbi_load(argv[1], &width, &height, &channels, 4);
if (!data) {
fprintf(stderr, "Error: Could not load \"%s\".\n", argv[1]);
exit(1);
}
int rx0 = -1, rx1, ry0, ry1;
for (int y = 0; y < height; y++) {
for (int x0 = 0; x0 < width - 3; x0++) {
if ((data[y * width + x0 + 0] & 0xFF) == 0x12
&& (data[y * width + x0 + 1] & 0xFF) == 0x34
&& (data[y * width + x0 + 2] & 0xFF) == 0x56
&& (data[y * width + x0 + 3] & 0xFF) == 0x78) {
for (int x1 = x0 + 4; x1 < width - 3; x1++) {
if ((data[y * width + x1 + 3] & 0xFF) == 0x12
&& (data[y * width + x1 + 2] & 0xFF) == 0x34
&& (data[y * width + x1 + 1] & 0xFF) == 0x56
&& (data[y * width + x1 + 0] & 0xFF) == 0x78) {
rx0 = x0, rx1 = x1 + 4, ry0 = y, ry1 = height;
// If a bottom marker is not found, assume the log spans the rest of the height of the image.
// (Some emulators might round the corners of the display, thus missing off a few pixels.)
for (int y1 = y + 1; y1 < height; y1++) {
if ((data[y1 * width + x1 + 3] & 0xFF) == 0x12
&& (data[y1 * width + x1 + 2] & 0xFF) == 0x34
&& (data[y1 * width + x1 + 1] & 0xFF) == 0x56
&& (data[y1 * width + x1 + 0] & 0xFF) == 0x78) {
ry1 = y1 + 1;
break;
}
}
goto foundMarkers;
}
}
}
}
}
foundMarkers:;
if (rx0 == -1) {
fprintf(stderr, "Error: Could not find log markers.\n");
exit(1);
}
uint8_t *output = (uint8_t *) malloc((rx1 - rx0) * (ry1 - ry0) * 2);
uintptr_t position = 0;
for (int y = ry0; y < ry1; y++) {
for (int x = rx0; x < rx1; x++) {
output[position++] = (data[y * width + x] & 0xFF0000) >> 16;
output[position++] = (data[y * width + x] & 0xFF00) >> 8;
}
}
printf("%s\n", output);
free(data);
return 0;
}

View File

@ -8,7 +8,7 @@ int position;
#define DEST_API_ARRAY "bin/generated_code/api_array.h"
#define DEST_SYSCALL_ARRAY "bin/generated_code/syscall_array.h"
#define DEST_ENUM_STRINGS_ARRAY "bin/generated_code/enum_strings_array.h"
#define DEST_DEPENDENCIES "bin/Dependency Files/api_header.d"
#define DEST_DEPENDENCIES "bin/dependency_files/api_header.d"
typedef struct Token {
#define TOKEN_IDENTIFIER (1)