Annotation of MiNT/src/debug.c, revision 1.1.1.6

1.1       root        1: /*
                      2: 
1.1.1.3   root        3: Copyright 1990,1991,1992 Eric R. Smith.
                      4: 
1.1.1.6 ! root        5: Copyright 1992,1993,1994 Atari Corporation.
1.1.1.3   root        6: 
                      7: All rights reserved.
1.1       root        8: 
                      9: */
                     10: 
                     11: 
                     12: 
                     13: /* MiNT debugging output routines */
                     14: 
                     15: /* also, ksprintf is put here, for lack of any better place to put it */
                     16: 
                     17: 
                     18: 
                     19: #include "mint.h"
                     20: 
                     21: #include <stdarg.h>
                     22: 
                     23: 
                     24: 
1.1.1.3   root       25: static void VDEBUGOUT P_((int, const char *, va_list));
1.1       root       26: 
1.1.1.6 ! root       27: int vksprintf(char *buf, const char *fmt, va_list args);
        !            28: 
1.1       root       29: 
                     30: 
                     31: /*
                     32: 
                     33:  * ksprintf implements a very crude sprintf() function that provides only
                     34: 
                     35:  * what MiNT needs...
                     36: 
                     37:  *
                     38: 
                     39:  * NOTE: this sprintf probably doesn't conform to any standard at
                     40: 
                     41:  * all. It's only use in life is that it won't overflow fixed
                     42: 
                     43:  * size buffers (i.e. it won't try to write more than SPRINTF_MAX
                     44: 
                     45:  * characters into a string)
                     46: 
                     47:  */
                     48: 
                     49: 
                     50: 
                     51: static int
                     52: 
                     53: PUTC(char *p, int c, int *cnt, int width) {
                     54: 
                     55:        int put = 1;
                     56: 
                     57: 
                     58: 
                     59:        if (*cnt <= 0) return 0;
                     60: 
                     61:        *p++ = c;
                     62: 
                     63:        *cnt -= 1;
                     64: 
                     65:        while (*cnt > 0 && --width > 0) {
                     66: 
                     67:                *p++ = ' ';
                     68: 
                     69:                *cnt -= 1;
                     70: 
                     71:                put++;
                     72: 
                     73:        }
                     74: 
                     75:        return put;
                     76: 
                     77: }
                     78: 
                     79: 
                     80: 
                     81: static int
                     82: 
                     83: PUTS(char *p, const char *s, int *cnt, int width) {
                     84: 
                     85:        int put = 0;
                     86: 
                     87: 
                     88: 
                     89:        if (s == 0) s = "(null)";
                     90: 
                     91: 
                     92: 
                     93:        while (*cnt > 0 && *s) {
                     94: 
                     95:                *p++ = *s++;
                     96: 
                     97:                put++;
                     98: 
                     99:                *cnt -= 1;
                    100: 
                    101:                width--;
                    102: 
                    103:        }
                    104: 
                    105:        while (width-- > 0 && *cnt > 0) {
                    106: 
                    107:                *p++ = ' ';
                    108: 
                    109:                put++;
                    110: 
                    111:                *cnt -= 1;
                    112: 
                    113:        }
                    114: 
                    115:        return put;
                    116: 
                    117: }
                    118: 
                    119: 
                    120: 
                    121: static int
                    122: 
                    123: PUTL(char *p, unsigned long u, int base, int *cnt, int width, int fill_char)
                    124: 
                    125: {
                    126: 
                    127:        int put = 0;
                    128: 
                    129:        static char obuf[32];
                    130: 
                    131:        char *t;
                    132: 
                    133: 
                    134: 
                    135:        t = obuf;
                    136: 
                    137: 
                    138: 
                    139:        do {
                    140: 
1.1.1.3   root      141:                *t++ = "0123456789ABCDEF"[u % base];
1.1       root      142: 
                    143:                u /= base;
                    144: 
                    145:                width--;
                    146: 
                    147:        } while (u > 0);
                    148: 
                    149: 
                    150: 
                    151:        while (width-- > 0 && *cnt > 0) {
                    152: 
                    153:                *p++ = fill_char;
                    154: 
                    155:                put++;
                    156: 
                    157:                *cnt -= 1;
                    158: 
                    159:        }
                    160: 
                    161:        while (*cnt > 0 && t != obuf) {
                    162: 
                    163:                *p++ = *--t;
                    164: 
                    165:                put++;
                    166: 
                    167:                *cnt -= 1;
                    168: 
                    169:        }
                    170: 
                    171:        return put;
                    172: 
                    173: }
                    174: 
                    175: 
                    176: 
                    177: int
                    178: 
                    179: vksprintf(char *buf, const char *fmt, va_list args)
                    180: 
                    181: {
                    182: 
                    183:        char *p = buf, c, fill_char;
                    184: 
                    185:        char *s_arg;
                    186: 
                    187:        int i_arg;
                    188: 
                    189:        long l_arg;
                    190: 
                    191:        int cnt;
                    192: 
                    193:        int width, long_flag;
                    194: 
                    195: 
                    196: 
                    197:        cnt = SPRINTF_MAX - 1;
                    198: 
                    199:        while( (c = *fmt++) != 0 ) {
                    200: 
                    201:                if (c != '%') {
                    202: 
                    203:                        p += PUTC(p, c, &cnt, 1);
                    204: 
                    205:                        continue;
                    206: 
                    207:                }
                    208: 
                    209:                c = *fmt++;
                    210: 
                    211:                width = 0;
                    212: 
                    213:                long_flag = 0;
                    214: 
                    215:                fill_char = ' ';
                    216: 
                    217:                if (c == '0') fill_char = '0';
                    218: 
                    219:                while (c && isdigit(c)) {
                    220: 
                    221:                        width = 10*width + (c-'0');
                    222: 
                    223:                        c = *fmt++;
                    224: 
                    225:                }
                    226: 
                    227:                if (c == 'l' || c == 'L') {
                    228: 
                    229:                        long_flag = 1;
                    230: 
                    231:                        c = *fmt++;
                    232: 
                    233:                }
                    234: 
                    235:                if (!c) break;
                    236: 
                    237: 
                    238: 
                    239:                switch (c) {
                    240: 
                    241:                case '%':
                    242: 
                    243:                        p += PUTC(p, c, &cnt, width);
                    244: 
                    245:                        break;
                    246: 
                    247:                case 'c':
                    248: 
                    249:                        i_arg = va_arg(args, int);
                    250: 
                    251:                        p += PUTC(p, i_arg, &cnt, width);
                    252: 
                    253:                        break;
                    254: 
                    255:                case 's':
                    256: 
                    257:                        s_arg = va_arg(args, char *);
                    258: 
                    259:                        p += PUTS(p, s_arg, &cnt, width);
                    260: 
                    261:                        break;
                    262: 
                    263:                case 'd':
                    264: 
                    265:                        if (long_flag) {
                    266: 
                    267:                                l_arg = va_arg(args, long);
                    268: 
                    269:                        } else {
                    270: 
                    271:                                l_arg = va_arg(args, int);
                    272: 
                    273:                        }
                    274: 
                    275:                        if (l_arg < 0) {
                    276: 
                    277:                                p += PUTC(p, '-', &cnt, 1);
                    278: 
                    279:                                width--;
                    280: 
                    281:                                l_arg = -l_arg;
                    282: 
                    283:                        }
                    284: 
                    285:                        p += PUTL(p, l_arg, 10, &cnt, width, fill_char);
                    286: 
                    287:                        break;
                    288: 
                    289:                case 'o':
                    290: 
                    291:                        if (long_flag) {
                    292: 
                    293:                                l_arg = va_arg(args, long);
                    294: 
                    295:                        } else {
                    296: 
                    297:                                l_arg = va_arg(args, unsigned int);
                    298: 
                    299:                        }
                    300: 
                    301:                        p += PUTL(p, l_arg, 8, &cnt, width, fill_char);
                    302: 
                    303:                        break;
                    304: 
                    305:                case 'x':
                    306: 
                    307:                        if (long_flag) {
                    308: 
                    309:                                l_arg = va_arg(args, long);
                    310: 
                    311:                        } else {
                    312: 
                    313:                                l_arg = va_arg(args, unsigned int);
                    314: 
                    315:                        }
                    316: 
                    317:                        p += PUTL(p, l_arg, 16, &cnt, width, fill_char);
                    318: 
                    319:                        break;
                    320: 
                    321:                case 'u':
                    322: 
                    323:                        if (long_flag) {
                    324: 
                    325:                                l_arg = va_arg(args, long);
                    326: 
                    327:                        } else {
                    328: 
                    329:                                l_arg = va_arg(args, unsigned int);
                    330: 
                    331:                        }
                    332: 
                    333:                        p += PUTL(p, l_arg, 10, &cnt, width, fill_char);
                    334: 
                    335:                        break;
                    336: 
                    337: 
                    338: 
                    339:                }
                    340: 
                    341:        }
                    342: 
                    343:        *p = 0;
                    344: 
1.1.1.2   root      345:        return (int)(p - buf);
1.1       root      346: 
                    347: }
                    348: 
                    349: 
                    350: 
1.1.1.2   root      351: int ARGS_ON_STACK 
1.1       root      352: 
                    353: ksprintf(char *buf, const char *fmt, ...)
                    354: 
                    355: {
                    356: 
                    357:        va_list args;
                    358: 
                    359:        int foo;
                    360: 
                    361: 
                    362: 
                    363:        va_start(args, fmt);
                    364: 
                    365:        foo = vksprintf(buf, fmt, args);        
                    366: 
                    367:        va_end(args);
                    368: 
                    369:        return foo;
                    370: 
                    371: }
                    372: 
                    373: 
                    374: 
1.1.1.3   root      375: int debug_level = 1;   /* how much debugging info should we print? */
1.1       root      376: 
                    377: int out_device = 2;    /* BIOS device to write errors to */
                    378: 
                    379: 
                    380: 
                    381: /*
                    382: 
                    383:  * out_next[i] is the out_device value to use when the current
                    384: 
                    385:  * device is i and the user hits F3.
                    386: 
                    387:  * Cycle is CON -> PRN -> AUX -> MIDI -> 6 -> 7 -> 8 -> 9 -> CON
                    388: 
                    389:  * (Note: BIOS devices 6-8 exist on Mega STe and TT, 9 on TT.)
                    390: 
                    391:  *
                    392: 
                    393:  * out_device and this table are exported to bios.c and used here in HALT().
                    394: 
                    395:  */
                    396: 
                    397: 
                    398: 
                    399: /*                 0  1  2  3  4  5  6  7  8  9 */
                    400: 
                    401: char out_next[] = { 1, 3, 0, 6, 0, 0, 7, 8, 9, 2 };
                    402: 
                    403: 
                    404: 
1.1.1.3   root      405: /*
                    406: 
                    407:  * debug log modes:
                    408: 
                    409:  *
                    410: 
                    411:  * 0: no logging.
                    412: 
                    413:  * 1: log all messages, dump the log any time something happens at
                    414: 
                    415:  *    a level that gets shown.  Thus, if you're at debug_level 2,
                    416: 
                    417:  *    everything is logged, and if something at levels 1 or 2 happens,
                    418: 
                    419:  *    the log is dumped.
                    420: 
                    421:  *
                    422: 
                    423:  * LB_LINE_LEN is 20 greater than SPRINTF_MAX because up to 20 bytes
                    424: 
                    425:  * are prepended to the buffer string passed to ksprintf.
                    426: 
                    427:  */
                    428: 
                    429: 
                    430: 
                    431: #define LBSIZE 50                              /* number of lines */
                    432: 
                    433: #define LB_LINE_LEN (SPRINTF_MAX+20)           /* width of a line */
                    434: 
                    435: int debug_logging;
                    436: 
                    437: int logptr;
                    438: 
                    439: static char logbuf[LBSIZE][LB_LINE_LEN];
                    440: 
                    441: static short logtime[LBSIZE];  /* low 16 bits of 200Hz: timestamp of msg */
                    442: 
                    443: 
                    444: 
                    445: /*
                    446: 
                    447:  * Extra terse settings - don't even output ALERTs unless asked to.
                    448: 
                    449:  *
                    450: 
                    451:  * Things that happen in on an idle Desktop are at LOW_LEVEL:
                    452: 
                    453:  * Psemaphore, Pmsg, Syield.
                    454: 
                    455:  */
                    456: 
1.1.1.6 ! root      457: #if 0  /* now in debug.h */
1.1.1.3   root      458: 
                    459: #define FORCE_LEVEL 0
                    460: 
                    461: #define ALERT_LEVEL 1
                    462: 
                    463: #define DEBUG_LEVEL 2
                    464: 
                    465: #define TRACE_LEVEL 3
                    466: 
                    467: #define LOW_LEVEL 4
                    468: 
1.1.1.6 ! root      469: #endif
        !           470: 
1.1.1.3   root      471: 
                    472: 
                    473: /*
                    474: 
                    475:  * The inner loop does this: at each newline, the keyboard is polled. If
                    476: 
                    477:  * you've hit a key, then it's checked: if it's ctl-alt, do_func_key is
                    478: 
                    479:  * called to do what it says, and that's that.  If not, then you pause the
                    480: 
                    481:  * output.  If you now hit a ctl-alt key, it gets done and you're still
                    482: 
                    483:  * paused.  Only hitting a non-ctl-alt key will get you out of the pause. 
                    484: 
                    485:  * (And only a non-ctl-alt key got you into it, too!)
                    486: 
                    487:  *
                    488: 
                    489:  * When out_device isn't the screen, number keys give you the same effects
                    490: 
                    491:  * as function keys.  The only way to get into this code, however, is to
                    492: 
                    493:  * have something produce debug output in the first place!  This is
                    494: 
                    495:  * awkward: Hit a key on out_device, then hit ctl-alt-F5 on the console so
                    496: 
                    497:  * bios.c will call DUMPPROC, which will call ALERT, which will call this.
                    498: 
                    499:  * It'll see the key you hit on out_device and drop you into this loop.
                    500: 
                    501:  * CTL-ALT keys make BIOS call do_func_key even when out_device isn't the
                    502: 
                    503:  * console.
                    504: 
                    505:  */
                    506: 
                    507: 
                    508: 
1.1       root      509: void
                    510: 
                    511: debug_ws(s)
                    512: 
                    513:        const char *s;
                    514: 
                    515: {
                    516: 
1.1.1.3   root      517:        long key;
                    518: 
                    519:        int scan;
                    520: 
                    521:        int stopped;
                    522: 
                    523: 
                    524: 
                    525:     while (*s) {
                    526: 
                    527:        (void)Bconout(out_device, *s);
                    528: 
                    529:        while (*s == '\n' && out_device != 0 && Bconstat(out_device)) {
1.1       root      530: 
1.1.1.3   root      531:            stopped = 0;
1.1       root      532: 
1.1.1.3   root      533:            while (1) {
1.1       root      534: 
1.1.1.3   root      535:                if (out_device == 2) {
1.1       root      536: 
1.1.1.5   root      537:                /* got a key; if ctl-alt then do it */
                    538: 
1.1.1.3   root      539:                    if ((Kbshift(-1) & 0x0c) == 0x0c) {
1.1       root      540: 
1.1.1.5   root      541:                        key = Bconin(out_device);
                    542: 
1.1.1.3   root      543:                        scan = (int) (((key >> 16) & 0xff));
1.1       root      544: 
1.1.1.3   root      545:                        do_func_key(scan);
1.1       root      546: 
1.1.1.5   root      547:                        goto ptoggle;
1.1       root      548: 
1.1.1.5   root      549:                    }
1.1       root      550: 
1.1.1.6 ! root      551:                    else goto cont;
        !           552: 
1.1.1.3   root      553:                }
                    554: 
                    555:                else {
                    556: 
1.1.1.5   root      557:                    key = Bconin(out_device);
                    558: 
1.1.1.3   root      559:                    if (key < '0' || key > '9') {
                    560: 
                    561: ptoggle:               /* not a func key */
                    562: 
                    563:                        if (stopped) break;
                    564: 
                    565:                        else stopped = 1;
1.1       root      566: 
1.1.1.3   root      567:                    }
1.1       root      568: 
1.1.1.3   root      569:                    else {
1.1       root      570: 
1.1.1.3   root      571:                        /* digit key from debug device == Fn */
1.1       root      572: 
1.1.1.3   root      573:                        if (key == '0') scan = 0x44;
                    574: 
                    575:                        else scan = (int) (key - '0' + 0x3a);
                    576: 
                    577:                        do_func_key(scan);
                    578: 
                    579:                    }
                    580: 
                    581:                }
1.1       root      582: 
1.1.1.3   root      583:            }
                    584: 
                    585:        }
                    586: 
1.1.1.6 ! root      587: cont:
        !           588: 
1.1.1.3   root      589:        s++;
                    590: 
                    591:     }
                    592: 
                    593: }
                    594: 
                    595: 
                    596: 
                    597: /*
                    598: 
                    599:  * _ALERT(s) returns 1 for success and 0 for failure.
                    600: 
                    601:  * It attempts to write the string to "the alert pipe," u:\pipe\alert.
                    602: 
                    603:  * If the write fails because the pipe is full, we "succeed" anyway.
                    604: 
                    605:  *
                    606: 
                    607:  * This is called in vdebugout and also in memprot.c for memory violations.
                    608: 
                    609:  * It's also used by the Salert() system call in dos.c.
                    610: 
                    611:  */
                    612: 
                    613: 
                    614: 
                    615: int
                    616: 
                    617: _ALERT(s)
                    618: 
                    619: char *s;
                    620: 
                    621: {
                    622: 
                    623:     FILEPTR *f;
                    624: 
                    625:     char alertbuf[SPRINTF_MAX+10], *ptr, *lastspace;
                    626: 
                    627:     int counter;
                    628: 
                    629:     char *alert;
                    630: 
                    631:     int olddebug = debug_level;
                    632: 
                    633:     int oldlogging = debug_logging;
                    634: 
                    635: 
                    636: 
                    637: /* temporarily reduce the debug level, so errors finding
                    638: 
                    639:  * u:\pipe\alert don't get reported
                    640: 
                    641:  */
                    642: 
                    643:     debug_level = debug_logging = 0;
                    644: 
                    645:     f = do_open("u:\\pipe\\alert",(O_WRONLY | O_NDELAY),0,(XATTR *)0);
                    646: 
                    647:     debug_level = olddebug;
                    648: 
                    649:     debug_logging = oldlogging;
                    650: 
                    651: 
                    652: 
                    653:     if (f) {
                    654: 
                    655: /*
                    656: 
                    657:  * format the string into an alert box
                    658: 
                    659:  */
                    660: 
                    661:        if (*s == '[') {        /* already an alert */
                    662: 
                    663:                alert = s;
                    664: 
                    665:        } else {
                    666: 
                    667:                alert = alertbuf;
                    668: 
                    669:                ksprintf(alertbuf, "[1][%s", s);
                    670: 
                    671: /*
                    672: 
                    673:  * make sure no lines exceed 30 characters; also, filter out any
                    674: 
                    675:  * reserved characters like '[' or ']'
                    676: 
                    677:  */
                    678: 
                    679:                ptr = alertbuf+4;
                    680: 
                    681:                counter = 0;
                    682: 
                    683:                lastspace = 0;
                    684: 
                    685:                while(*ptr) {
                    686: 
                    687:                        if (*ptr == ' ') {
                    688: 
                    689:                                lastspace = ptr;
                    690: 
                    691:                        } else if (*ptr == '[') {
                    692: 
                    693:                                *ptr = '(';
                    694: 
                    695:                        } else if (*ptr == ']') {
                    696: 
                    697:                                *ptr = ')';
                    698: 
                    699:                        } else if (*ptr == '|') {
                    700: 
                    701:                                *ptr = ':';
1.1       root      702: 
                    703:                        }
                    704: 
1.1.1.3   root      705:                        if (counter++ >= 29) {
                    706: 
                    707:                                if (lastspace) {
                    708: 
                    709:                                        *lastspace = '|';
                    710: 
                    711:                                        counter = (int) (ptr - lastspace);
                    712: 
                    713:                                        lastspace = 0;
                    714: 
                    715:                                } else {
                    716: 
                    717:                                        *ptr = '|';
                    718: 
                    719:                                        counter = 0;
                    720: 
                    721:                                }
                    722: 
                    723:                        }
                    724: 
                    725:                        ptr++;
                    726: 
1.1       root      727:                }
                    728: 
1.1.1.3   root      729:                strcpy(ptr, "][  OK  ]");
1.1       root      730: 
                    731:        }
                    732: 
1.1.1.3   root      733: 
                    734: 
                    735:        (*f->dev->write)(f,alert,(long)strlen(alert)+1);
                    736: 
                    737:        do_close(f);
                    738: 
                    739:        return 1;
                    740: 
                    741:     }
                    742: 
                    743:     else return 0;
                    744: 
1.1       root      745: }
                    746: 
                    747: 
                    748: 
                    749: static void
                    750: 
1.1.1.3   root      751: VDEBUGOUT(level, s, args)
                    752: 
                    753:        int level;
1.1       root      754: 
                    755:        const char *s;
                    756: 
                    757:        va_list args;
                    758: 
                    759: {
                    760: 
1.1.1.3   root      761:        char *lp;
                    762: 
                    763:        char *lptemp;
                    764: 
                    765: 
                    766: 
                    767:        logtime[logptr] = (short)(*(long *)0x4baL);
                    768: 
                    769:        lp = logbuf[logptr];
                    770: 
                    771:        if (++logptr == LBSIZE) logptr = 0;
                    772: 
                    773: 
                    774: 
                    775:        if (curproc) {
                    776: 
                    777:            ksprintf(lp,"pid %3d (%s): ", curproc->pid, curproc->name);
                    778: 
                    779:            lptemp = lp+strlen(lp);
                    780: 
                    781:        }
                    782: 
                    783:        else {
                    784: 
                    785:            lptemp = lp;
                    786: 
                    787:        }
                    788: 
                    789: 
                    790: 
                    791:        vksprintf(lptemp, s, args);
                    792: 
                    793: 
                    794: 
                    795:        /* for alerts, try the alert pipe unconditionally */
                    796: 
                    797:        if (level == ALERT_LEVEL && _ALERT(lp)) return;
                    798: 
                    799: 
                    800: 
                    801:        if (debug_level >= level) {
                    802: 
                    803:                debug_ws(lp);
                    804: 
                    805:                debug_ws("\r\n");
                    806: 
                    807:        }
                    808: 
                    809: }
                    810: 
                    811: 
                    812: 
                    813: void ARGS_ON_STACK Tracelow(const char *s, ...)
                    814: 
                    815: {
                    816: 
                    817:        va_list args;
1.1       root      818: 
                    819: 
                    820: 
1.1.1.3   root      821:        if (debug_logging || (debug_level >= LOW_LEVEL)) {
1.1       root      822: 
1.1.1.3   root      823:                va_start(args, s);
1.1       root      824: 
1.1.1.3   root      825:                VDEBUGOUT(LOW_LEVEL, s, args);
1.1       root      826: 
1.1.1.3   root      827:                va_end(args);
1.1       root      828: 
1.1.1.3   root      829:        }
1.1       root      830: 
                    831: }
                    832: 
                    833: 
                    834: 
1.1.1.2   root      835: void ARGS_ON_STACK Trace(const char *s, ...)
1.1       root      836: 
                    837: {
                    838: 
                    839:        va_list args;
                    840: 
                    841: 
                    842: 
1.1.1.3   root      843:        if (debug_logging || (debug_level >= TRACE_LEVEL)) {
1.1       root      844: 
                    845:                va_start(args, s);
                    846: 
1.1.1.3   root      847:                VDEBUGOUT(TRACE_LEVEL, s, args);
1.1       root      848: 
                    849:                va_end(args);
                    850: 
                    851:        }
                    852: 
                    853: }
                    854: 
                    855: 
                    856: 
1.1.1.2   root      857: void ARGS_ON_STACK Debug(const char *s, ...)
1.1       root      858: 
                    859: {
                    860: 
                    861:        va_list args;
                    862: 
                    863: 
                    864: 
1.1.1.3   root      865:        if (debug_logging || (debug_level >= DEBUG_LEVEL)) {
1.1       root      866: 
                    867:                va_start(args, s);
                    868: 
1.1.1.3   root      869:                VDEBUGOUT(DEBUG_LEVEL, s, args);
1.1       root      870: 
                    871:                va_end(args);
                    872: 
                    873:        }
                    874: 
1.1.1.3   root      875:        if (debug_logging && debug_level >= DEBUG_LEVEL) DUMPLOG();
                    876: 
1.1       root      877: }
                    878: 
                    879: 
                    880: 
1.1.1.2   root      881: void ARGS_ON_STACK ALERT(const char *s, ...)
1.1       root      882: 
                    883: {
                    884: 
                    885:        va_list args;
                    886: 
                    887: 
                    888: 
1.1.1.3   root      889:        if (debug_logging || debug_level >= ALERT_LEVEL) {
                    890: 
                    891:            va_start(args, s);
                    892: 
                    893:            VDEBUGOUT(ALERT_LEVEL, s, args);
                    894: 
                    895:            va_end(args);
                    896: 
                    897:        }
                    898: 
                    899:        if (debug_logging && debug_level >= ALERT_LEVEL) DUMPLOG();
                    900: 
                    901: }
                    902: 
                    903: 
                    904: 
                    905: void ARGS_ON_STACK FORCE(const char *s, ...)
                    906: 
                    907: {
                    908: 
                    909:        va_list args;
                    910: 
                    911: 
                    912: 
1.1       root      913:        va_start(args, s);
                    914: 
1.1.1.3   root      915:        VDEBUGOUT(FORCE_LEVEL, s, args);
1.1       root      916: 
                    917:        va_end(args);
                    918: 
1.1.1.3   root      919:        /* don't dump log here - hardly ever what you mean to do. */
                    920: 
1.1       root      921: }
                    922: 
                    923: 
                    924: 
1.1.1.3   root      925: void
                    926: 
                    927: DUMPLOG()
                    928: 
                    929: {
                    930: 
                    931:        char *end;
                    932: 
                    933:        char *start;
                    934: 
                    935:        short *timeptr;
                    936: 
                    937:        char timebuf[6];
                    938: 
                    939: 
                    940: 
                    941:        /* logbuf[logptr] is the oldest string here */
                    942: 
                    943: 
                    944: 
                    945:        end = start = logbuf[logptr];
                    946: 
                    947:        timeptr = &logtime[logptr];
                    948: 
                    949: 
                    950: 
                    951:        do {
                    952: 
                    953:            if (*start) {
                    954: 
                    955:                ksprintf(timebuf,"%04x ",*timeptr);
                    956: 
                    957:                debug_ws(timebuf);
                    958: 
                    959:                debug_ws(start);
                    960: 
                    961:                debug_ws("\r\n");
                    962: 
                    963:                *start = '\0';
                    964: 
                    965:            }
                    966: 
                    967:            start += LB_LINE_LEN;
                    968: 
                    969:            timeptr++;
                    970: 
                    971: #ifdef LATTICE
                    972: 
                    973: #pragma ignore 83      /* [reference beyond object size] */
                    974: 
                    975: #endif
                    976: 
                    977:            if (start == logbuf[LBSIZE]) {
                    978: 
                    979: #ifdef LATTICE
                    980: 
                    981: #pragma warning 83     /* [reference beyond object size] */
                    982: 
                    983: #endif
                    984: 
                    985:                start = logbuf[0];
                    986: 
                    987:                timeptr = &logtime[0];
                    988: 
                    989:            }
                    990: 
                    991:         } while (start != end);
                    992: 
                    993: 
                    994: 
                    995:         logptr = 0;
                    996: 
                    997: }
                    998: 
                    999: 
                   1000: 
                   1001: /* wait for a key to be pressed */
                   1002: 
                   1003: void
                   1004: 
                   1005: PAUSE()
                   1006: 
                   1007: {
                   1008: 
                   1009:        debug_ws("Hit a key\r\n");
                   1010: 
                   1011:        (void)Bconin(2);
                   1012: 
                   1013: }
                   1014: 
                   1015:   
                   1016: 
1.1       root     1017: EXITING
                   1018: 
1.1.1.2   root     1019: void ARGS_ON_STACK FATAL(const char *s, ...)
1.1       root     1020: 
                   1021: {
                   1022: 
                   1023:        va_list args;
                   1024: 
                   1025: 
                   1026: 
                   1027:        va_start(args, s);
                   1028: 
1.1.1.3   root     1029:        VDEBUGOUT(-1, s, args);
1.1       root     1030: 
                   1031:        va_end(args);
                   1032: 
1.1.1.3   root     1033:        if (debug_logging) {
                   1034: 
                   1035:                DUMPLOG();
                   1036: 
                   1037:        }
                   1038: 
                   1039: 
                   1040: 
1.1       root     1041:        HALT();
                   1042: 
                   1043: }
                   1044: 
                   1045: 
                   1046: 
                   1047: 
                   1048: 
1.1.1.4   root     1049: static const char *rebootmsg[MAXLANG] = {
                   1050: 
                   1051: "FATAL ERROR. You must reboot the system.\r\n",
                   1052: 
                   1053: "FATALER FEHLER. Das System mu� neu gestartet werden.\r\n",    /* German */
                   1054: 
                   1055: "FATAL ERROR. You must reboot the system.\r\n",                /* French */
                   1056: 
                   1057: "FATAL ERROR. You must reboot the system.\r\n",                /* UK */
                   1058: 
                   1059: "FATAL ERROR. You must reboot the system.\r\n",                /* Spanish */
                   1060: 
                   1061: "FATAL ERROR. You must reboot the system.\r\n"         /* Italian */
                   1062: 
                   1063: };
                   1064: 
                   1065: 
                   1066: 
1.1       root     1067: EXITING 
                   1068: 
                   1069: void HALT()
                   1070: 
                   1071: {
                   1072: 
                   1073:        long r;
                   1074: 
1.1.1.3   root     1075:        long key;
                   1076: 
                   1077:        int scan;
                   1078: 
1.1       root     1079:        extern long tosssp;     /* in main.c */
                   1080: 
1.1.1.3   root     1081: #ifdef PROFILING
1.1       root     1082: 
1.1.1.6 ! root     1083:        extern EXITING _exit P_((int)) NORETURN;
1.1.1.3   root     1084: 
                   1085: #endif
1.1       root     1086: 
                   1087:        restr_intr();   /* restore interrupts to normal */
                   1088: 
1.1.1.4   root     1089: #ifdef DEBUG_INFO
                   1090: 
1.1       root     1091:        debug_ws("Fatal MiNT error: adjust debug level and hit a key...\r\n");
                   1092: 
1.1.1.4   root     1093: #else
                   1094: 
                   1095:        debug_ws(rebootmsg[gl_lang]);
                   1096: 
                   1097: #endif
                   1098: 
1.1       root     1099:        sys_q[READY_Q] = 0;     /* prevent context switches */
                   1100: 
                   1101: 
                   1102: 
                   1103:        for(;;) {
                   1104: 
1.1.1.3   root     1105:                /* get a key; if ctl-alt then do it, else halt */
1.1       root     1106: 
1.1.1.3   root     1107:                key = Bconin(out_device);
1.1       root     1108: 
1.1.1.3   root     1109:                if ((key & 0x0c000000L) == 0x0c000000L) {
1.1       root     1110: 
1.1.1.3   root     1111:                        scan = (int) ((key >> 16) & 0xff);
1.1       root     1112: 
1.1.1.3   root     1113:                        do_func_key(scan);
1.1.1.2   root     1114: 
                   1115:                }
                   1116: 
1.1.1.3   root     1117:                else {
1.1       root     1118: 
                   1119:                        break;
                   1120: 
1.1.1.3   root     1121:                }
                   1122: 
1.1       root     1123:        }
                   1124: 
                   1125:        for(;;) {
                   1126: 
1.1.1.4   root     1127:                debug_ws(rebootmsg[gl_lang]);
1.1       root     1128: 
                   1129:                r = Bconin(2);
                   1130: 
                   1131: 
                   1132: 
                   1133:                if ( (r & 0x0ff) == 'x' ) {
                   1134: 
1.1.1.4   root     1135:                        extern int no_mem_prot;
                   1136: 
1.1       root     1137:                        close_filesys();
                   1138: 
1.1.1.4   root     1139:                        if (!no_mem_prot)
                   1140: 
                   1141:                                restr_mmu();
                   1142: 
1.1.1.5   root     1143:                        restr_screen();
                   1144: 
1.1       root     1145:                        (void)Super((void *)tosssp);    /* gratuitous (void *) for Lattice */
                   1146: 
1.1.1.2   root     1147: #ifdef PROFILING
                   1148: 
                   1149:                        _exit(0);
                   1150: 
                   1151: #else
                   1152: 
                   1153:                        Pterm0();
                   1154: 
                   1155: #endif
1.1       root     1156: 
                   1157:                }
                   1158: 
                   1159:        }
                   1160: 
                   1161: }
                   1162: 
                   1163: 
                   1164: 
                   1165: 
                   1166: 
                   1167: /* some key definitions */
                   1168: 
                   1169: #define CTRLALT 0xc
                   1170: 
                   1171: #define DEL 0x53       /* scan code of delete key */
                   1172: 
                   1173: #define UNDO 0x61      /* scan code of undo key */
                   1174: 
                   1175: 
                   1176: 
                   1177: void
                   1178: 
                   1179: do_func_key(scan)
                   1180: 
                   1181:        int scan;
                   1182: 
                   1183: {
                   1184: 
                   1185:        extern struct tty con_tty;
                   1186: 
                   1187: 
                   1188: 
                   1189:        switch (scan) {
                   1190: 
                   1191:        case DEL:
                   1192: 
                   1193:                reboot();
                   1194: 
                   1195:                break;
                   1196: 
                   1197:        case UNDO:
                   1198: 
1.1.1.6 ! root     1199:                killgroup(con_tty.pgrp, SIGQUIT, 1);
1.1       root     1200: 
                   1201:                break;
                   1202: 
1.1.1.4   root     1203: #ifdef DEBUG_INFO
1.1.1.2   root     1204: 
1.1.1.3   root     1205:        case 0x3b:              /* F1: increase debugging level */
1.1       root     1206: 
                   1207:                debug_level++;
                   1208: 
                   1209:                break;
                   1210: 
1.1.1.3   root     1211:        case 0x3c:              /* F2: reduce debugging level */
1.1       root     1212: 
                   1213:                if (debug_level > 0)
                   1214: 
                   1215:                        --debug_level;
                   1216: 
                   1217:                break;
                   1218: 
1.1.1.3   root     1219:        case 0x3d:              /* F3: cycle out_device */
1.1       root     1220: 
                   1221:                out_device = out_next[out_device];
                   1222: 
                   1223:                break;
                   1224: 
1.1.1.3   root     1225:        case 0x3e:              /* F4: set out_device to console */
1.1       root     1226: 
                   1227:                out_device = 2;
                   1228: 
                   1229:                break;
                   1230: 
1.1.1.3   root     1231:        case 0x3f:              /* F5: dump memory */
                   1232: 
1.1.1.5   root     1233:                DUMP_ALL_MEM();
                   1234: 
                   1235:                break;
1.1       root     1236: 
1.1.1.5   root     1237:        case 0x58:              /* shift+F5: dump kernel allocated memory */
1.1       root     1238: 
1.1.1.5   root     1239:                NALLOC_DUMP();
1.1.1.2   root     1240: 
1.1       root     1241:                break;
                   1242: 
1.1.1.3   root     1243:        case 0x40:              /* F6: dump processes */
1.1       root     1244: 
                   1245:                DUMPPROC();
                   1246: 
                   1247:                break;
                   1248: 
1.1.1.3   root     1249:        case 0x41:              /* F7: toggle debug_logging */
                   1250: 
                   1251:                debug_logging ^= 1;
                   1252: 
                   1253:                break;
                   1254: 
                   1255:        case 0x42:              /* F8: dump log */
                   1256: 
                   1257:                DUMPLOG();
                   1258: 
                   1259:                break;
                   1260: 
                   1261:        case 0x43:              /* F9: dump the global memory table */
                   1262: 
                   1263:                QUICKDUMP();
                   1264: 
                   1265:                break;
                   1266: 
                   1267:        case 0x5c:              /* shift-F9: dump the mmu tree */
                   1268: 
                   1269:                BIG_MEM_DUMP(1,curproc);
                   1270: 
                   1271:                break;
                   1272: 
                   1273:        case 0x44:              /* F10: do an annotated dump of memory */
                   1274: 
                   1275:                BIG_MEM_DUMP(0,0);
                   1276: 
                   1277:                break;
                   1278: 
1.1.1.2   root     1279: #endif
                   1280: 
1.1       root     1281:        }
                   1282: 
                   1283: }
                   1284: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.