clang-format
This commit is contained in:
@@ -37,10 +37,9 @@
|
||||
#include <current.h>
|
||||
#include <synch.h>
|
||||
#include <mainbus.h>
|
||||
#include <vfs.h> // for vfs_sync()
|
||||
#include <vfs.h> // for vfs_sync()
|
||||
#include <lamebus/ltrace.h> // for ltrace_stop()
|
||||
|
||||
|
||||
/* Flags word for DEBUG() macro. */
|
||||
uint32_t dbflags = 0;
|
||||
|
||||
@@ -50,79 +49,66 @@ static struct lock *kprintf_lock;
|
||||
/* Lock for polled kprintfs */
|
||||
static struct spinlock kprintf_spinlock;
|
||||
|
||||
|
||||
/*
|
||||
* Warning: all this has to work from interrupt handlers and when
|
||||
* interrupts are disabled.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Create the kprintf lock. Must be called before creating a second
|
||||
* thread or enabling a second CPU.
|
||||
*/
|
||||
void
|
||||
kprintf_bootstrap(void)
|
||||
{
|
||||
KASSERT(kprintf_lock == NULL);
|
||||
void kprintf_bootstrap(void) {
|
||||
KASSERT(kprintf_lock == NULL);
|
||||
|
||||
kprintf_lock = lock_create("kprintf_lock");
|
||||
if (kprintf_lock == NULL) {
|
||||
panic("Could not create kprintf_lock\n");
|
||||
}
|
||||
spinlock_init(&kprintf_spinlock);
|
||||
kprintf_lock = lock_create("kprintf_lock");
|
||||
if (kprintf_lock == NULL) {
|
||||
panic("Could not create kprintf_lock\n");
|
||||
}
|
||||
spinlock_init(&kprintf_spinlock);
|
||||
}
|
||||
|
||||
/*
|
||||
* Send characters to the console. Backend for __printf.
|
||||
*/
|
||||
static
|
||||
void
|
||||
console_send(void *junk, const char *data, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
static void console_send(void *junk, const char *data, size_t len) {
|
||||
size_t i;
|
||||
|
||||
(void)junk;
|
||||
(void)junk;
|
||||
|
||||
for (i=0; i<len; i++) {
|
||||
putch(data[i]);
|
||||
}
|
||||
for (i = 0; i < len; i++) {
|
||||
putch(data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Printf to the console.
|
||||
*/
|
||||
int
|
||||
kprintf(const char *fmt, ...)
|
||||
{
|
||||
int chars;
|
||||
va_list ap;
|
||||
bool dolock;
|
||||
int kprintf(const char *fmt, ...) {
|
||||
int chars;
|
||||
va_list ap;
|
||||
bool dolock;
|
||||
|
||||
dolock = kprintf_lock != NULL
|
||||
&& curthread->t_in_interrupt == false
|
||||
&& curthread->t_curspl == 0
|
||||
&& curcpu->c_spinlocks == 0;
|
||||
dolock = kprintf_lock != NULL && curthread->t_in_interrupt == false &&
|
||||
curthread->t_curspl == 0 && curcpu->c_spinlocks == 0;
|
||||
|
||||
if (dolock) {
|
||||
lock_acquire(kprintf_lock);
|
||||
}
|
||||
else {
|
||||
spinlock_acquire(&kprintf_spinlock);
|
||||
}
|
||||
if (dolock) {
|
||||
lock_acquire(kprintf_lock);
|
||||
} else {
|
||||
spinlock_acquire(&kprintf_spinlock);
|
||||
}
|
||||
|
||||
va_start(ap, fmt);
|
||||
chars = __vprintf(console_send, NULL, fmt, ap);
|
||||
va_end(ap);
|
||||
va_start(ap, fmt);
|
||||
chars = __vprintf(console_send, NULL, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (dolock) {
|
||||
lock_release(kprintf_lock);
|
||||
}
|
||||
else {
|
||||
spinlock_release(&kprintf_spinlock);
|
||||
}
|
||||
if (dolock) {
|
||||
lock_release(kprintf_lock);
|
||||
} else {
|
||||
spinlock_release(&kprintf_spinlock);
|
||||
}
|
||||
|
||||
return chars;
|
||||
return chars;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -130,87 +116,83 @@ kprintf(const char *fmt, ...)
|
||||
* passed and then halts the system.
|
||||
*/
|
||||
|
||||
void
|
||||
panic(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
void panic(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
|
||||
/*
|
||||
* When we reach panic, the system is usually fairly screwed up.
|
||||
* It's not entirely uncommon for anything else we try to do
|
||||
* here to trigger more panics.
|
||||
*
|
||||
* This variable makes sure that if we try to do something here,
|
||||
* and it causes another panic, *that* panic doesn't try again;
|
||||
* trying again almost inevitably causes infinite recursion.
|
||||
*
|
||||
* This is not excessively paranoid - these things DO happen!
|
||||
*/
|
||||
static volatile int evil;
|
||||
/*
|
||||
* When we reach panic, the system is usually fairly screwed up.
|
||||
* It's not entirely uncommon for anything else we try to do
|
||||
* here to trigger more panics.
|
||||
*
|
||||
* This variable makes sure that if we try to do something here,
|
||||
* and it causes another panic, *that* panic doesn't try again;
|
||||
* trying again almost inevitably causes infinite recursion.
|
||||
*
|
||||
* This is not excessively paranoid - these things DO happen!
|
||||
*/
|
||||
static volatile int evil;
|
||||
|
||||
if (evil == 0) {
|
||||
evil = 1;
|
||||
if (evil == 0) {
|
||||
evil = 1;
|
||||
|
||||
/*
|
||||
* Not only do we not want to be interrupted while
|
||||
* panicking, but we also want the console to be
|
||||
* printing in polling mode so as not to do context
|
||||
* switches. So turn interrupts off on this CPU.
|
||||
*/
|
||||
splhigh();
|
||||
}
|
||||
/*
|
||||
* Not only do we not want to be interrupted while
|
||||
* panicking, but we also want the console to be
|
||||
* printing in polling mode so as not to do context
|
||||
* switches. So turn interrupts off on this CPU.
|
||||
*/
|
||||
splhigh();
|
||||
}
|
||||
|
||||
if (evil == 1) {
|
||||
evil = 2;
|
||||
if (evil == 1) {
|
||||
evil = 2;
|
||||
|
||||
/* Kill off other threads and halt other CPUs. */
|
||||
thread_panic();
|
||||
}
|
||||
/* Kill off other threads and halt other CPUs. */
|
||||
thread_panic();
|
||||
}
|
||||
|
||||
if (evil == 2) {
|
||||
evil = 3;
|
||||
if (evil == 2) {
|
||||
evil = 3;
|
||||
|
||||
/* Print the message. */
|
||||
kprintf("panic: ");
|
||||
va_start(ap, fmt);
|
||||
__vprintf(console_send, NULL, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
/* Print the message. */
|
||||
kprintf("panic: ");
|
||||
va_start(ap, fmt);
|
||||
__vprintf(console_send, NULL, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
if (evil == 3) {
|
||||
evil = 4;
|
||||
if (evil == 3) {
|
||||
evil = 4;
|
||||
|
||||
/* Drop to the debugger. */
|
||||
ltrace_stop(0);
|
||||
}
|
||||
/* Drop to the debugger. */
|
||||
ltrace_stop(0);
|
||||
}
|
||||
|
||||
if (evil == 4) {
|
||||
evil = 5;
|
||||
if (evil == 4) {
|
||||
evil = 5;
|
||||
|
||||
/* Try to sync the disks. */
|
||||
vfs_sync();
|
||||
}
|
||||
/* Try to sync the disks. */
|
||||
vfs_sync();
|
||||
}
|
||||
|
||||
if (evil == 5) {
|
||||
evil = 6;
|
||||
if (evil == 5) {
|
||||
evil = 6;
|
||||
|
||||
/* Shut down or reboot the system. */
|
||||
mainbus_panic();
|
||||
}
|
||||
/* Shut down or reboot the system. */
|
||||
mainbus_panic();
|
||||
}
|
||||
|
||||
/*
|
||||
* Last resort, just in case.
|
||||
*/
|
||||
/*
|
||||
* Last resort, just in case.
|
||||
*/
|
||||
|
||||
for (;;);
|
||||
for (;;)
|
||||
;
|
||||
}
|
||||
|
||||
/*
|
||||
* Assertion failures go through this.
|
||||
*/
|
||||
void
|
||||
badassert(const char *expr, const char *file, int line, const char *func)
|
||||
{
|
||||
panic("Assertion failed: %s, at %s:%d (%s)\n",
|
||||
expr, file, line, func);
|
||||
void badassert(const char *expr, const char *file, int line, const char *func) {
|
||||
panic("Assertion failed: %s, at %s:%d (%s)\n", expr, file, line, func);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user