|
|
1.1 ! root 1: /* ! 2: * Mach Operating System ! 3: * Copyright (c) 1993 Carnegie Mellon University ! 4: * All Rights Reserved. ! 5: * ! 6: * Permission to use, copy, modify and distribute this software and its ! 7: * documentation is hereby granted, provided that both the copyright ! 8: * notice and this permission notice appear in all copies of the ! 9: * software, derivative works or modified versions, and any portions ! 10: * thereof, and that both notices appear in supporting documentation. ! 11: * ! 12: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" ! 13: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR ! 14: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. ! 15: * ! 16: * Carnegie Mellon requests users of this software to return to ! 17: * ! 18: * Software Distribution Coordinator or [email protected] ! 19: * School of Computer Science ! 20: * Carnegie Mellon University ! 21: * Pittsburgh PA 15213-3890 ! 22: * ! 23: * any improvements or extensions that they make and grant Carnegie Mellon ! 24: * the rights to redistribute these changes. ! 25: */ ! 26: ! 27: #include <mach_kdb.h> ! 28: #include <norma_ipc.h> ! 29: #include <cpus.h> ! 30: ! 31: #include "cpu_number.h" ! 32: #include <kern/lock.h> ! 33: #include <sys/varargs.h> ! 34: #include <kern/thread.h> ! 35: ! 36: ! 37: ! 38: extern void cnputc(); ! 39: void Debugger(); ! 40: ! 41: #if MACH_KDB ! 42: extern int db_breakpoints_inserted; ! 43: #endif ! 44: ! 45: #if NCPUS>1 ! 46: simple_lock_data_t Assert_print_lock; /* uninited, we take our chances */ ! 47: #endif ! 48: ! 49: void ! 50: Assert(char *exp, char *file, int line) ! 51: { ! 52: #if NCPUS > 1 ! 53: simple_lock(&Assert_print_lock); ! 54: printf("{%d} Assertion failed: file \"%s\", line %d\n", ! 55: cpu_number(), file, line); ! 56: simple_unlock(&Assert_print_lock); ! 57: #else ! 58: printf("Assertion `%s' failed in file \"%s\", line %d\n", ! 59: exp, file, line); ! 60: #endif ! 61: ! 62: #if MACH_KDB ! 63: if (db_breakpoints_inserted) ! 64: #endif ! 65: Debugger("assertion failure"); ! 66: } ! 67: ! 68: void Debugger(message) ! 69: char * message; ! 70: { ! 71: #if !MACH_KDB ! 72: panic("Debugger invoked, but there isn't one!"); ! 73: #endif ! 74: ! 75: #ifdef lint ! 76: message++; ! 77: #endif /* lint */ ! 78: ! 79: #if defined(vax) || defined(PC532) ! 80: asm("bpt"); ! 81: #endif /* vax */ ! 82: ! 83: #ifdef sun3 ! 84: current_thread()->pcb->flag |= TRACE_KDB; ! 85: asm("orw #0x00008000,sr"); ! 86: #endif /* sun3 */ ! 87: #ifdef sun4 ! 88: current_thread()->pcb->pcb_flag |= TRACE_KDB; ! 89: asm("ta 0x81"); ! 90: #endif /* sun4 */ ! 91: ! 92: #if defined(mips ) || defined(luna88k) || defined(i860) || defined(alpha) ! 93: gimmeabreak(); ! 94: #endif ! 95: ! 96: #ifdef i386 ! 97: asm("int3"); ! 98: #endif ! 99: } ! 100: ! 101: /* Be prepared to panic anytime, ! 102: even before panic_init() gets called from the "normal" place in kern/startup.c. ! 103: (panic_init() still needs to be called from there ! 104: to make sure we get initialized before starting multiple processors.) */ ! 105: boolean_t panic_lock_initialized = FALSE; ! 106: decl_simple_lock_data(, panic_lock) ! 107: ! 108: char *panicstr; ! 109: int paniccpu; ! 110: ! 111: void ! 112: panic_init() ! 113: { ! 114: if (!panic_lock_initialized) ! 115: { ! 116: panic_lock_initialized = TRUE; ! 117: simple_lock_init(&panic_lock); ! 118: } ! 119: } ! 120: ! 121: /*VARARGS1*/ ! 122: void ! 123: panic(s, va_alist) ! 124: char * s; ! 125: va_dcl ! 126: { ! 127: va_list listp; ! 128: #if NORMA_IPC ! 129: extern int _node_self; /* node_self() may not be callable yet */ ! 130: #endif /* NORMA_IPC */ ! 131: ! 132: panic_init(); ! 133: ! 134: simple_lock(&panic_lock); ! 135: if (panicstr) { ! 136: if (cpu_number() != paniccpu) { ! 137: simple_unlock(&panic_lock); ! 138: halt_cpu(); ! 139: /* NOTREACHED */ ! 140: } ! 141: } ! 142: else { ! 143: panicstr = s; ! 144: paniccpu = cpu_number(); ! 145: } ! 146: simple_unlock(&panic_lock); ! 147: printf("panic"); ! 148: #if NORMA_IPC ! 149: printf("(node %U)", _node_self); ! 150: #endif ! 151: #if NCPUS > 1 ! 152: printf("(cpu %U)", paniccpu); ! 153: #endif ! 154: printf(": "); ! 155: va_start(listp); ! 156: _doprnt(s, &listp, cnputc, 0); ! 157: va_end(listp); ! 158: printf("\n"); ! 159: ! 160: /* Give the user time to see the message */ ! 161: { ! 162: int i = 60; /* seconds */ ! 163: while (i--) ! 164: delay (1000000); /* microseconds */ ! 165: } ! 166: ! 167: #if MACH_KDB ! 168: Debugger("panic"); ! 169: #else ! 170: halt_all_cpus (1); ! 171: #endif ! 172: } ! 173: ! 174: /* ! 175: * We'd like to use BSD's log routines here... ! 176: */ ! 177: /*VARARGS2*/ ! 178: void ! 179: log(level, fmt, va_alist) ! 180: int level; ! 181: char * fmt; ! 182: va_dcl ! 183: { ! 184: va_list listp; ! 185: ! 186: #ifdef lint ! 187: level++; ! 188: #endif ! 189: va_start(listp); ! 190: _doprnt(fmt, &listp, cnputc, 0); ! 191: va_end(listp); ! 192: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.