Annotation of researchv9/sys/boot/stand/prf.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * @(#)prf.c 1.1 86/02/03 Copyright (c) 1985 by Sun Microsystems, Inc.
        !             3:  */
        !             4: 
        !             5: #include <sys/types.h>
        !             6: #include <machine/sunromvec.h>
        !             7: 
        !             8: /*
        !             9:  * Scaled down version of C Library printf.
        !            10:  * Used to print diagnostic information directly on console tty.
        !            11:  * Since it is not interrupt driven, all system activities are
        !            12:  * suspended.  Printf should not be used for chit-chat.
        !            13:  *
        !            14:  * One additional format: %b is supported to decode error registers.
        !            15:  * Usage is:
        !            16:  *     printf("reg=%b\n", regval, "<base><arg>*");
        !            17:  * Where <base> is the output base expressed as a control character,
        !            18:  * e.g. \10 gives octal; \20 gives hex.  Each arg is a sequence of
        !            19:  * characters, the first of which gives the bit number to be inspected
        !            20:  * (origin 1), and the next characters (up to a control character, i.e.
        !            21:  * a character <= 32), give the name of the register.  Thus
        !            22:  *     printf("reg=%b\n", 3, "\10\2BITTWO\1BITONE\n");
        !            23:  * would produce output:
        !            24:  *     reg=2<BITTWO,BITONE>
        !            25:  */
        !            26: /*VARARGS1*/
        !            27: printf(fmt, x1)
        !            28:        char *fmt;
        !            29:        unsigned x1;
        !            30: {
        !            31: 
        !            32:        prf(fmt, &x1);
        !            33: }
        !            34: 
        !            35: prf(fmt, adx)
        !            36:        register char *fmt;
        !            37:        register u_int *adx;
        !            38: {
        !            39:        register int b, c, i;
        !            40:        register char *s;
        !            41:        register int any;
        !            42: 
        !            43: loop:
        !            44:        while ((c = *fmt++) != '%') {
        !            45:                if(c == '\0')
        !            46:                        return;
        !            47:                putchar(c);
        !            48:        }
        !            49: again:
        !            50:        c = *fmt++;
        !            51:        switch (c) {
        !            52: 
        !            53:        case 'l':
        !            54:                goto again;
        !            55:        case 'x': case 'X':
        !            56:                b = 16;
        !            57:                goto number;
        !            58:        case 'd': case 'D':
        !            59:        case 'u':               /* what a joke */
        !            60:                b = 10;
        !            61:                goto number;
        !            62:        case 'o': case 'O':
        !            63:                b = 8;
        !            64: number:
        !            65:                printn((u_long)*adx, b);
        !            66:                break;
        !            67:        case 'c':
        !            68:                b = *adx;
        !            69:                putchar(b);
        !            70:                break;
        !            71:        case 'b':
        !            72:                b = *adx++;
        !            73:                s = (char *)*adx;
        !            74:                printn((u_long)b, *s++);
        !            75:                any = 0;
        !            76:                if (b) {
        !            77:                        putchar('<');
        !            78:                        while (i = *s++) {
        !            79:                                if (b & (1 << (i-1))) {
        !            80:                                        if (any)
        !            81:                                                putchar(',');
        !            82:                                        any = 1;
        !            83:                                        for (; (c = *s) > 32; s++)
        !            84:                                                putchar(c);
        !            85:                                } else
        !            86:                                        for (; *s > 32; s++)
        !            87:                                                ;
        !            88:                        }
        !            89:                        putchar('>');
        !            90:                }
        !            91:                break;
        !            92: 
        !            93:        case 's':
        !            94:                s = (char *)*adx;
        !            95:                while (c = *s++)
        !            96:                        putchar(c);
        !            97:                break;
        !            98:        }
        !            99:        adx++;
        !           100:        goto loop;
        !           101: }
        !           102: 
        !           103: /*
        !           104:  * Printn prints a number n in base b.
        !           105:  * We don't use recursion to avoid deep kernel stacks.
        !           106:  */
        !           107: printn(n, b)
        !           108:        register u_long n;
        !           109:        register short b;
        !           110: {
        !           111:        char prbuf[11];
        !           112:        register char *cp;
        !           113: 
        !           114:        if (b == 10 && (int)n < 0) {
        !           115:                putchar('-');
        !           116:                n = (unsigned)(-(int)n);
        !           117:        }
        !           118:        cp = prbuf;
        !           119:        do {
        !           120:                *cp++ = "0123456789abcdef"[n%b];
        !           121:                n /= b;
        !           122:        } while (n);
        !           123:        do
        !           124:                putchar(*--cp);
        !           125:        while (cp > prbuf);
        !           126: }
        !           127: 
        !           128: /*
        !           129:  * Print a character on console.
        !           130:  */
        !           131: putchar(c)
        !           132:        int c;
        !           133: {
        !           134: 
        !           135:        (*romp->v_putchar)(c);
        !           136: }

unix.superglobalmegacorp.com

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