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

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

unix.superglobalmegacorp.com

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