Annotation of MiNT/src/debugold.c, revision 1.1

1.1     ! root        1: /*
        !             2: 
        !             3: Copyright 1990,1991,1992 Eric R. Smith. All rights reserved.
        !             4: 
        !             5: */
        !             6: 
        !             7: 
        !             8: 
        !             9: /* MiNT debugging output routines */
        !            10: 
        !            11: /* also, ksprintf is put here, for lack of any better place to put it */
        !            12: 
        !            13: 
        !            14: 
        !            15: #include "mint.h"
        !            16: 
        !            17: #include <stdarg.h>
        !            18: 
        !            19: 
        !            20: 
        !            21: static void VDEBUGOUT P_((char *, va_list));
        !            22: 
        !            23: 
        !            24: 
        !            25: /*
        !            26: 
        !            27:  * ksprintf implements a very crude sprintf() function that provides only
        !            28: 
        !            29:  * what MiNT needs...
        !            30: 
        !            31:  *
        !            32: 
        !            33:  * NOTE: this sprintf probably doesn't conform to any standard at
        !            34: 
        !            35:  * all. It's only use in life is that it won't overflow fixed
        !            36: 
        !            37:  * size buffers (i.e. it won't try to write more than SPRINTF_MAX
        !            38: 
        !            39:  * characters into a string)
        !            40: 
        !            41:  */
        !            42: 
        !            43: 
        !            44: 
        !            45: static int
        !            46: 
        !            47: PUTC(p, c, cnt, width)
        !            48: 
        !            49:        char *p;
        !            50: 
        !            51:        int c;
        !            52: 
        !            53:        int *cnt;
        !            54: 
        !            55:        int width;
        !            56: 
        !            57: {
        !            58: 
        !            59:        int put = 1;
        !            60: 
        !            61: 
        !            62: 
        !            63:        if (*cnt <= 0) return 0;
        !            64: 
        !            65:        *p++ = c;
        !            66: 
        !            67:        *cnt -= 1;
        !            68: 
        !            69:        while (*cnt > 0 && --width > 0) {
        !            70: 
        !            71:                *p++ = ' ';
        !            72: 
        !            73:                *cnt -= 1;
        !            74: 
        !            75:                put++;
        !            76: 
        !            77:        }
        !            78: 
        !            79:        return put;
        !            80: 
        !            81: }
        !            82: 
        !            83: 
        !            84: 
        !            85: static int
        !            86: 
        !            87: PUTS(p, s, cnt, width)
        !            88: 
        !            89:        char *p, *s;
        !            90: 
        !            91:        int *cnt;
        !            92: 
        !            93:        int width;
        !            94: 
        !            95: {
        !            96: 
        !            97:        int put = 0;
        !            98: 
        !            99: 
        !           100: 
        !           101:        while (*cnt > 0 && *s) {
        !           102: 
        !           103:                *p++ = *s++;
        !           104: 
        !           105:                put++;
        !           106: 
        !           107:                *cnt -= 1;
        !           108: 
        !           109:                width--;
        !           110: 
        !           111:        }
        !           112: 
        !           113:        while (width-- > 0 && *cnt > 0) {
        !           114: 
        !           115:                *p++ = ' ';
        !           116: 
        !           117:                put++;
        !           118: 
        !           119:                *cnt -= 1;
        !           120: 
        !           121:        }
        !           122: 
        !           123:        return put;
        !           124: 
        !           125: }
        !           126: 
        !           127: 
        !           128: 
        !           129: static int
        !           130: 
        !           131: PUTL(p, u, base, cnt, width, fill_char)
        !           132: 
        !           133:        char *p;
        !           134: 
        !           135:        unsigned long u;
        !           136: 
        !           137:        int base;
        !           138: 
        !           139:        int *cnt;
        !           140: 
        !           141:        int width;
        !           142: 
        !           143:        int fill_char;
        !           144: 
        !           145: {
        !           146: 
        !           147:        int put = 0;
        !           148: 
        !           149:        static char obuf[32];
        !           150: 
        !           151:        char *t;
        !           152: 
        !           153: 
        !           154: 
        !           155:        t = obuf;
        !           156: 
        !           157: 
        !           158: 
        !           159:        do {
        !           160: 
        !           161:                *t++ = "0123456789abcdef"[u % base];
        !           162: 
        !           163:                u /= base;
        !           164: 
        !           165:                width--;
        !           166: 
        !           167:        } while (u > 0);
        !           168: 
        !           169: 
        !           170: 
        !           171:        while (width-- > 0 && *cnt > 0) {
        !           172: 
        !           173:                *p++ = fill_char;
        !           174: 
        !           175:                put++;
        !           176: 
        !           177:                *cnt -= 1;
        !           178: 
        !           179:        }
        !           180: 
        !           181:        while (*cnt > 0 && t != obuf) {
        !           182: 
        !           183:                *p++ = *--t;
        !           184: 
        !           185:                put++;
        !           186: 
        !           187:                *cnt -= 1;
        !           188: 
        !           189:        }
        !           190: 
        !           191:        return put;
        !           192: 
        !           193: }
        !           194: 
        !           195: 
        !           196: 
        !           197: int
        !           198: 
        !           199: vksprintf(buf, fmt, args)
        !           200: 
        !           201:        char *buf;
        !           202: 
        !           203:        const char *fmt;
        !           204: 
        !           205:        va_list args;
        !           206: 
        !           207: {
        !           208: 
        !           209:        char *p = buf, c, fill_char;
        !           210: 
        !           211:        char *s_arg;
        !           212: 
        !           213:        int i_arg;
        !           214: 
        !           215:        long l_arg;
        !           216: 
        !           217:        int cnt;
        !           218: 
        !           219:        int width, long_flag;
        !           220: 
        !           221: 
        !           222: 
        !           223:        cnt = SPRINTF_MAX - 1;
        !           224: 
        !           225:        while( (c = *fmt++) != 0 ) {
        !           226: 
        !           227:                if (c != '%') {
        !           228: 
        !           229:                        p += PUTC(p, c, &cnt, 1);
        !           230: 
        !           231:                        continue;
        !           232: 
        !           233:                }
        !           234: 
        !           235:                c = *fmt++;
        !           236: 
        !           237:                width = 0;
        !           238: 
        !           239:                long_flag = 0;
        !           240: 
        !           241:                fill_char = ' ';
        !           242: 
        !           243:                if (c == '0') fill_char = '0';
        !           244: 
        !           245:                while (c && isdigit(c)) {
        !           246: 
        !           247:                        width = 10*width + (c-'0');
        !           248: 
        !           249:                        c = *fmt++;
        !           250: 
        !           251:                }
        !           252: 
        !           253:                if (c == 'l' || c == 'L') {
        !           254: 
        !           255:                        long_flag = 1;
        !           256: 
        !           257:                        c = *fmt++;
        !           258: 
        !           259:                }
        !           260: 
        !           261:                if (!c) break;
        !           262: 
        !           263: 
        !           264: 
        !           265:                switch (c) {
        !           266: 
        !           267:                case '%':
        !           268: 
        !           269:                        p += PUTC(p, c, &cnt, width);
        !           270: 
        !           271:                        break;
        !           272: 
        !           273:                case 'c':
        !           274: 
        !           275:                        i_arg = va_arg(args, int);
        !           276: 
        !           277:                        p += PUTC(p, i_arg, &cnt, width);
        !           278: 
        !           279:                        break;
        !           280: 
        !           281:                case 's':
        !           282: 
        !           283:                        s_arg = va_arg(args, char *);
        !           284: 
        !           285:                        p += PUTS(p, s_arg, &cnt, width);
        !           286: 
        !           287:                        break;
        !           288: 
        !           289:                case 'd':
        !           290: 
        !           291:                        if (long_flag) {
        !           292: 
        !           293:                                l_arg = va_arg(args, long);
        !           294: 
        !           295:                        } else {
        !           296: 
        !           297:                                l_arg = va_arg(args, int);
        !           298: 
        !           299:                        }
        !           300: 
        !           301:                        if (l_arg < 0) {
        !           302: 
        !           303:                                p += PUTC(p, '-', &cnt, 1);
        !           304: 
        !           305:                                width--;
        !           306: 
        !           307:                                l_arg = -l_arg;
        !           308: 
        !           309:                        }
        !           310: 
        !           311:                        p += PUTL(p, l_arg, 10, &cnt, width, fill_char);
        !           312: 
        !           313:                        break;
        !           314: 
        !           315:                case 'o':
        !           316: 
        !           317:                        if (long_flag) {
        !           318: 
        !           319:                                l_arg = va_arg(args, long);
        !           320: 
        !           321:                        } else {
        !           322: 
        !           323:                                l_arg = va_arg(args, unsigned int);
        !           324: 
        !           325:                        }
        !           326: 
        !           327:                        p += PUTL(p, l_arg, 8, &cnt, width, fill_char);
        !           328: 
        !           329:                        break;
        !           330: 
        !           331:                case 'x':
        !           332: 
        !           333:                        if (long_flag) {
        !           334: 
        !           335:                                l_arg = va_arg(args, long);
        !           336: 
        !           337:                        } else {
        !           338: 
        !           339:                                l_arg = va_arg(args, unsigned int);
        !           340: 
        !           341:                        }
        !           342: 
        !           343:                        p += PUTL(p, l_arg, 16, &cnt, width, fill_char);
        !           344: 
        !           345:                        break;
        !           346: 
        !           347:                case 'u':
        !           348: 
        !           349:                        if (long_flag) {
        !           350: 
        !           351:                                l_arg = va_arg(args, long);
        !           352: 
        !           353:                        } else {
        !           354: 
        !           355:                                l_arg = va_arg(args, unsigned int);
        !           356: 
        !           357:                        }
        !           358: 
        !           359:                        p += PUTL(p, l_arg, 10, &cnt, width, fill_char);
        !           360: 
        !           361:                        break;
        !           362: 
        !           363: 
        !           364: 
        !           365:                }
        !           366: 
        !           367:        }
        !           368: 
        !           369:        *p = 0;
        !           370: 
        !           371:        return (p - buf);
        !           372: 
        !           373: }
        !           374: 
        !           375: 
        !           376: 
        !           377: int
        !           378: 
        !           379: ksprintf(buf, fmt)
        !           380: 
        !           381:        char *buf;
        !           382: 
        !           383:        const char *fmt;
        !           384: 
        !           385: {
        !           386: 
        !           387:        va_list args;
        !           388: 
        !           389:        int foo;
        !           390: 
        !           391: 
        !           392: 
        !           393:        va_start(args, fmt);
        !           394: 
        !           395:        foo = vksprintf(buf, fmt, args);        
        !           396: 
        !           397:        va_end(args);
        !           398: 
        !           399:        return foo;
        !           400: 
        !           401: }
        !           402: 
        !           403: 
        !           404: 
        !           405: int debug_level = 0;   /* how much debugging info should we print? */
        !           406: 
        !           407: int out_device = 2;    /* BIOS device to write errors to */
        !           408: 
        !           409: 
        !           410: 
        !           411: /*
        !           412: 
        !           413:  * out_next[i] is the out_device value to use when the current
        !           414: 
        !           415:  * device is i and the user hits F3.
        !           416: 
        !           417:  * Cycle is CON -> PRN -> AUX -> MIDI -> 6 -> 7 -> 8 -> 9 -> CON
        !           418: 
        !           419:  * (Note: BIOS devices 6-8 exist on Mega STe and TT, 9 on TT.)
        !           420: 
        !           421:  *
        !           422: 
        !           423:  * out_device and this table are exported to bios.c and used here in HALT().
        !           424: 
        !           425:  */
        !           426: 
        !           427: 
        !           428: 
        !           429: /*                 0  1  2  3  4  5  6  7  8  9 */
        !           430: 
        !           431: char out_next[] = { 1, 3, 0, 6, 0, 0, 7, 8, 9, 2 };
        !           432: 
        !           433: 
        !           434: 
        !           435: void
        !           436: 
        !           437: debug_ws(s)
        !           438: 
        !           439:        char *s;
        !           440: 
        !           441: {
        !           442: 
        !           443:        while (*s) {
        !           444: 
        !           445:                (void)Bconout(out_device, *s);
        !           446: 
        !           447:                if (*s == '\n' && out_device != 0 && Bconstat(out_device)) {
        !           448: 
        !           449:                        (void)Bconin(out_device);
        !           450: 
        !           451:                        while (!Bconstat(out_device)) ;
        !           452: 
        !           453:                        (void)Bconin(out_device);
        !           454: 
        !           455:                }
        !           456: 
        !           457:                s++;
        !           458: 
        !           459:        }
        !           460: 
        !           461: }
        !           462: 
        !           463: 
        !           464: 
        !           465: static void
        !           466: 
        !           467: VDEBUGOUT(s, args)
        !           468: 
        !           469:        char *s;
        !           470: 
        !           471:        va_list args;
        !           472: 
        !           473: {
        !           474: 
        !           475:        char buf[SPRINTF_MAX];
        !           476: 
        !           477: 
        !           478: 
        !           479:        ksprintf(buf, "pid %d (%s): ", curproc->pid, curproc->name);
        !           480: 
        !           481:        debug_ws(buf);
        !           482: 
        !           483:        vksprintf(buf, s, args);
        !           484: 
        !           485:        debug_ws(buf);
        !           486: 
        !           487:        debug_ws("\r\n");
        !           488: 
        !           489: }
        !           490: 
        !           491: 
        !           492: 
        !           493: void TRACE(s)
        !           494: 
        !           495:        char *s;
        !           496: 
        !           497: {
        !           498: 
        !           499:        va_list args;
        !           500: 
        !           501: 
        !           502: 
        !           503:        if (debug_level > 1) {
        !           504: 
        !           505:                va_start(args, s);
        !           506: 
        !           507:                VDEBUGOUT(s, args);
        !           508: 
        !           509:                va_end(args);
        !           510: 
        !           511:        }
        !           512: 
        !           513: }
        !           514: 
        !           515: 
        !           516: 
        !           517: void DEBUG(s)
        !           518: 
        !           519:        char *s;
        !           520: 
        !           521: {
        !           522: 
        !           523:        va_list args;
        !           524: 
        !           525: 
        !           526: 
        !           527:        if (debug_level) {
        !           528: 
        !           529:                va_start(args, s);
        !           530: 
        !           531:                VDEBUGOUT(s, args);
        !           532: 
        !           533:                va_end(args);
        !           534: 
        !           535:        }
        !           536: 
        !           537: }
        !           538: 
        !           539: 
        !           540: 
        !           541: void ALERT(s)
        !           542: 
        !           543:        char *s;
        !           544: 
        !           545: {
        !           546: 
        !           547:        va_list args;
        !           548: 
        !           549: 
        !           550: 
        !           551:        va_start(args, s);
        !           552: 
        !           553:        VDEBUGOUT(s, args);
        !           554: 
        !           555:        va_end(args);
        !           556: 
        !           557: }
        !           558: 
        !           559: 
        !           560: 
        !           561: EXITING
        !           562: 
        !           563: void FATAL(s)
        !           564: 
        !           565:        char *s;
        !           566: 
        !           567: {
        !           568: 
        !           569:        va_list args;
        !           570: 
        !           571: 
        !           572: 
        !           573:        va_start(args, s);
        !           574: 
        !           575:        VDEBUGOUT(s, args);
        !           576: 
        !           577:        va_end(args);
        !           578: 
        !           579:        HALT();
        !           580: 
        !           581: }
        !           582: 
        !           583: 
        !           584: 
        !           585: 
        !           586: 
        !           587: EXITING 
        !           588: 
        !           589: void HALT()
        !           590: 
        !           591: {
        !           592: 
        !           593:        long r;
        !           594: 
        !           595:        extern long tosssp;     /* in main.c */
        !           596: 
        !           597: 
        !           598: 
        !           599:        restr_intr();   /* restore interrupts to normal */
        !           600: 
        !           601:        debug_ws("Fatal MiNT error: adjust debug level and hit a key...\r\n");
        !           602: 
        !           603:        sys_q[READY_Q] = 0;     /* prevent context switches */
        !           604: 
        !           605: 
        !           606: 
        !           607:        for(;;) {
        !           608: 
        !           609:                r = Bconin(2) & 0x00ff0000;
        !           610: 
        !           611:                if (r == 0x3b0000)
        !           612: 
        !           613:                        debug_level++;
        !           614: 
        !           615:                else if (r == 0x3c0000)
        !           616: 
        !           617:                        --debug_level;
        !           618: 
        !           619:                else if (r == 0x3d0000)         /* F3: cycle to next device */
        !           620: 
        !           621:                        out_device = out_next[out_device];
        !           622: 
        !           623:                else if (r == 0x3e0000)
        !           624: 
        !           625:                        out_device = 2;         /* F4: reset to console */
        !           626: 
        !           627:                else if (r == 0x3f0000)
        !           628: 
        !           629:                        DUMPMEM(core);          /* F5: dump memory */
        !           630: 
        !           631:                else if (r == 0x400000) 
        !           632: 
        !           633:                        DUMPPROC();
        !           634: 
        !           635:                else
        !           636: 
        !           637:                        break;
        !           638: 
        !           639:        }
        !           640: 
        !           641:        for(;;) {
        !           642: 
        !           643:        debug_ws("System halted. Press 'x' to exit, or else reboot\r\n");
        !           644: 
        !           645:                r = Bconin(2);
        !           646: 
        !           647: 
        !           648: 
        !           649:                if ( (r & 0x0ff) == 'x' ) {
        !           650: 
        !           651:                        close_filesys();
        !           652: 
        !           653:                        (void)Super(tosssp);
        !           654: 
        !           655:                        zeroexit();
        !           656: 
        !           657:                }
        !           658: 
        !           659:        }
        !           660: 
        !           661: }
        !           662: 
        !           663: 
        !           664: 
        !           665: /* some key definitions */
        !           666: 
        !           667: #define CTRLALT 0xc
        !           668: 
        !           669: #define DEL 0x53       /* scan code of delete key */
        !           670: 
        !           671: #define UNDO 0x61      /* scan code of undo key */
        !           672: 
        !           673: 
        !           674: 
        !           675: void
        !           676: 
        !           677: do_func_key(scan)
        !           678: 
        !           679:        int scan;
        !           680: 
        !           681: {
        !           682: 
        !           683:        extern struct tty con_tty;
        !           684: 
        !           685: 
        !           686: 
        !           687:        switch (scan) {
        !           688: 
        !           689:        case DEL:
        !           690: 
        !           691:                reboot();
        !           692: 
        !           693:                break;
        !           694: 
        !           695:        case UNDO:
        !           696: 
        !           697:                killgroup(con_tty.pgrp, SIGQUIT);
        !           698: 
        !           699:                break;
        !           700: 
        !           701:        case 0x3b:              /* F1 */
        !           702: 
        !           703:                debug_level++;
        !           704: 
        !           705:                break;
        !           706: 
        !           707:        case 0x3c:              /* F2 */
        !           708: 
        !           709:                if (debug_level > 0)
        !           710: 
        !           711:                        --debug_level;
        !           712: 
        !           713:                break;
        !           714: 
        !           715:        case 0x3d:              /* F3 */
        !           716: 
        !           717:                out_device = out_next[out_device];
        !           718: 
        !           719:                break;
        !           720: 
        !           721:        case 0x3e:              /* F4 */
        !           722: 
        !           723:                out_device = 2;
        !           724: 
        !           725:                break;
        !           726: 
        !           727:        case 0x3f:              /* F5 */
        !           728: 
        !           729:                DUMPMEM(core);
        !           730: 
        !           731:                break;
        !           732: 
        !           733:        case 0x40:              /* F6 */
        !           734: 
        !           735:                DUMPPROC();
        !           736: 
        !           737:                break;
        !           738: 
        !           739:        }
        !           740: 
        !           741: }
        !           742: 
        !           743: 
        !           744: 

unix.superglobalmegacorp.com

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