diff --git a/kaleid/kernel/buf/bprint.c b/kaleid/kernel/buf/bprint.c index a75ee22..1c49fd3 100644 --- a/kaleid/kernel/buf/bprint.c +++ b/kaleid/kernel/buf/bprint.c @@ -25,6 +25,7 @@ #include extern error_t bputc(Buffer_t *buf, uchar ch); +error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap); // // Prints formatted string on buf according to fmt @@ -35,11 +36,25 @@ error_t BPrintOnBuf(Buffer_t *buf, const char *fmt, ...) va_list ap; va_start(ap, fmt); - rc = BPrintOnBufV(buf, fmt, ap); + ExAcquireLock(&buf->lock); + rc = vbprintf(buf, fmt, ap); + ExReleaseLock(&buf->lock); va_end(ap); return rc; } + +error_t BPrintOnBufV(Buffer_t *buf, const char *fmt, va_list ap) +{ + error_t rc; + + ExAcquireLock(&buf->lock); + rc = vbprintf(buf, fmt, ap); + ExReleaseLock(&buf->lock); + + return rc; +} + // // Prints 0 for octal, 0x for hexadecimal, 0b for binary // @@ -81,10 +96,10 @@ static error_t bdopadding(Buffer_t *buf, size_t width, size_t len, #define fmtnext() do{fmt++;if(*fmt==0){rc=EINVAL;goto leave;}}while(0) // -// Actually does BPrintOnBuf's job +// Actually does BPrintOnBuf's job; doesn't lock anything // Quite a long function // -error_t BPrintOnBufV(Buffer_t *buf, const char *fmt, va_list ap) +error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap) { error_t rc = EOK; int tmpwidth; @@ -120,8 +135,6 @@ error_t BPrintOnBufV(Buffer_t *buf, const char *fmt, va_list ap) return EBADF; } - ExAcquireLock(&buf->lock); - //----------------------------------------------------------------------------// // We come back here after dealing with a modifier @@ -367,7 +380,6 @@ loop: //----------------------------------------------------------------------------// leave: - ExReleaseLock(&buf->lock); return rc; } diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 2e63b1a..7121469 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -147,18 +147,18 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic) // Sanity checks and hello world BtInitSanity(mbMagic); - //Memory mapping + // Memory mapping MmInitMemoryMap(); + // Heap initialization MmInitHeap(); - //int i = 0; - //while(i < 512) { KernLog("%d\n", i++);} - //MmPrintMemoryMap(); - PsInitSched(); // We're out PsFiniSched(); - KeCrashSystem(); //yay + + KeStartPanic("Test Panic %d", 4); + + KeCrashSystem(); } diff --git a/kaleid/kernel/io/vga.c b/kaleid/kernel/io/vga.c index 6956df9..0230143 100644 --- a/kaleid/kernel/io/vga.c +++ b/kaleid/kernel/io/vga.c @@ -44,9 +44,7 @@ error_t bvgaflusher(Buffer_t *buf) ushort *fbp = BtGetBootInfo(video).framebufferAddr; const uchar color = 0xf; - assert(buf->lastLF == 0); - - uchar *currentLine = buf->wp - buf->lineLen; + uchar *currentLine = buf->wp - buf->lineLen - buf->lastLF; uchar *ptr = (uchar *)lmax((size_t)buf->buf, (size_t)currentLine - (buf->nLines - 1) * buf->lineLen); diff --git a/kaleid/kernel/ke/panic.c b/kaleid/kernel/ke/panic.c index 52555f3..c6cbb5a 100644 --- a/kaleid/kernel/ke/panic.c +++ b/kaleid/kernel/ke/panic.c @@ -28,6 +28,8 @@ #include #include +error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap); + // // Failed assert() handler // @@ -55,21 +57,29 @@ noreturn void KeStartPanic(const char *fmt, ...) PsCurProc = NULL; if (BStdOut == NULL) KeCrashSystem(); + ExAttemptLock(&BStdOut->lock); + if (fmt == NULL) { fmt = "(no message given)"; } if (KePanicStr[0] != 0) { - KernLog("\nDouble panic!"); + vbprintf(BStdOut, "\nDouble panic!", NULL); KeHaltCPU(); } + + KePanicStr[0] = 1; + // We don't check vbprintf's output + // If it fails, what could we do anyway? + + vbprintf(BStdOut, "\nPanic!\n\n", NULL); + va_start(ap, fmt); - vsnprintf((char *)KePanicStr, PANICSTR_SIZE, fmt, ap); + vbprintf(BStdOut, fmt, ap); va_end(ap); - - KernLog("\nPanic!\n\n"); - KernLog((char *)KePanicStr); + + BStdOut->flusher(BStdOut); KeHaltCPU(); }