# 2.11BSD#431 - /usr/src/sys/sys/subr_prf.c

##### Functions

    harderr           X
    log               X
    logpri            X
    panic             X
    prf               X
    printf            X
    printn            X
    putchar           X
    tablefull         X
    tprintf           X
    uprintf           X

##### Variables

    panicstr          X

##### Macros

    TOCONS            X
    TOLOG             X
    TOTTY             X

       1: /*
       2:  * Copyright (c) 1986 Regents of the University of California.
       3:  * All rights reserved.  The Berkeley software License Agreement
       4:  * specifies the terms and conditions for redistribution.
       5:  *
       6:  *	@(#)subr_prf.c	1.2 (2.11BSD) 1998/12/5
       7:  */
       8:
       9: #include "param.h"
      10: #include "user.h"
      11: #include "machine/seg.h"
      12: #include "buf.h"
      13: #include "msgbuf.h"
      14: #include "conf.h"
      15: #include "ioctl.h"
      16: #include "tty.h"
      17: #include "reboot.h"
      18: #include "systm.h"
      19: #include "syslog.h"
      20:
      21: #define TOCONS  0x1
      22: #define TOTTY   0x2
      23: #define TOLOG   0x4
      24:
      25: /*
      26:  * In case console is off,
      27:  * panicstr contains argument to last
      28:  * call to panic.
      29:  */
      30: char    *panicstr;
      31:
      32: /*
      33:  * Scaled down version of C Library printf.
      34:  * Used to print diagnostic information directly on console tty.
      35:  * Since it is not interrupt driven, all system activities are
      36:  * suspended.  Printf should not be used for chit-chat.
      37:  *
      38:  * One additional format: %b is supported to decode error registers.
      39:  * Usage is:
      40:  *	printf("reg=%b\n", regval, "<base><arg>*");
      41:  * Where <base> is the output base expressed as a control character,
      42:  * e.g. \10 gives octal; \20 gives hex.  Each arg is a sequence of
      43:  * characters, the first of which gives the bit number to be inspected
      44:  * (origin 1), and the next characters (up to a control character, i.e.
      45:  * a character <= 32), give the name of the register.  Thus
      46:  *	printf("reg=%b\n", 3, "\10\2BITTWO\1BITONE\n");
      47:  * would produce output:
      48:  *	reg=3<BITTWO,BITONE>
      49:  */
      50:
      51: /*VARARGS1*/
      52: printf(fmt, x1)
      53:     char *fmt;
      54:     unsigned x1;
      55: {
      56:     prf(fmt, &x1, TOCONS | TOLOG, (struct tty *)0);
      57: }
      58:
      59: /*
      60:  * Uprintf prints to the current user's terminal,
      61:  * guarantees not to sleep (so could be called by interrupt routines;
      62:  * but prints on the tty of the current process)
      63:  * and does no watermark checking - (so no verbose messages).
      64:  * NOTE: with current kernel mapping scheme, the user structure is
      65:  * not guaranteed to be accessible at interrupt level (see seg.h);
      66:  * a savemap/restormap would be needed here or in putchar if uprintf
      67:  * was to be used at interrupt time.
      68:  */
      69: /*VARARGS1*/
      70: uprintf(fmt, x1)
      71:     char    *fmt;
      72:     unsigned x1;
      73: {
      74:     register struct tty *tp;
      75:
      76:     if ((tp = u.u_ttyp) == NULL)
      77:         return;
      78:
      79:     if (ttycheckoutq(tp, 1))
      80:         prf(fmt, &x1, TOTTY, tp);
      81: }
      82:
      83: /*
      84:  * tprintf prints on the specified terminal (console if none)
      85:  * and logs the message.  It is designed for error messages from
      86:  * single-open devices, and may be called from interrupt level
      87:  * (does not sleep).
      88:  */
      89: /*VARARGS2*/
      90: tprintf(tp, fmt, x1)
      91:     register struct tty *tp;
      92:     char *fmt;
      93:     unsigned x1;
      94: {
      95:     int flags = TOTTY | TOLOG;
      96:     extern struct tty cons;
      97:
      98:     logpri(LOG_INFO);
      99:     if (tp == (struct tty *)NULL)
     100:         tp = &cons;
     101:     if (ttycheckoutq(tp, 0) == 0)
     102:         flags = TOLOG;
     103:     prf(fmt, &x1, flags, tp);
     104:     logwakeup(logMSG);
     105: }
     106:
     107: /*
     108:  * Log writes to the log buffer,
     109:  * and guarantees not to sleep (so can be called by interrupt routines).
     110:  * If there is no process reading the log yet, it writes to the console also.
     111:  */
     112: /*VARARGS2*/
     113: log(level, fmt, x1)
     114:     char *fmt;
     115:     unsigned x1;
     116: {
     117:     register s = splhigh();
     118:
     119:     logpri(level);
     120:     prf(fmt, &x1, TOLOG, (struct tty *)0);
     121:     splx(s);
     122:     if (!logisopen(logMSG))
     123:         prf(fmt, &x1, TOCONS, (struct tty *)0);
     124:     logwakeup(logMSG);
     125: }
     126:
     127: logpri(level)
     128:     int level;
     129: {
     130:
     131:     putchar('<', TOLOG, (struct tty *)0);
     132:     printn((u_long)level, 10, TOLOG, (struct tty *)0);
     133:     putchar('>', TOLOG, (struct tty *)0);
     134: }
     135:
     136: prf(fmt, adx, flags, ttyp)
     137:     register char *fmt;
     138:     register u_int *adx;
     139:     int flags;
     140:     struct tty *ttyp;
     141: {
     142:     register int c;
     143:     u_int b;
     144:     char *s;
     145:     int i, any;
     146:
     147: loop:
     148:     while ((c = *fmt++) != '%') {
     149:         if (c == '\0')
     150:             return;
     151:         putchar(c, flags, ttyp);
     152:     }
     153:     c = *fmt++;
     154:     switch (c) {
     155:
     156:     case 'l':
     157:         c = *fmt++;
     158:         switch(c) {
     159:             case 'x':
     160:                 b = 16;
     161:                 goto lnumber;
     162:             case 'd':
     163:                 b = 10;
     164:                 goto lnumber;
     165:             case 'o':
     166:                 b = 8;
     167:                 goto lnumber;
     168:             default:
     169:                 putchar('%', flags, ttyp);
     170:                 putchar('l', flags, ttyp);
     171:                 putchar(c, flags, ttyp);
     172:         }
     173:         break;
     174:     case 'X':
     175:         b = 16;
     176:         goto lnumber;
     177:     case 'D':
     178:         b = 10;
     179:         goto lnumber;
     180:     case 'O':
     181:         b = 8;
     182: lnumber:    printn(*(long *)adx, b, flags, ttyp);
     183:         adx += (sizeof(long) / sizeof(int)) - 1;
     184:         break;
     185:     case 'x':
     186:         b = 16;
     187:         goto number;
     188:     case 'd':
     189:     case 'u':       /* what a joke */
     190:         b = 10;
     191:         goto number;
     192:     case 'o':
     193:         b = 8;
     194: number:     printn((long)*adx, b, flags, ttyp);
     195:         break;
     196:     case 'c':
     197:         putchar(*adx, flags, ttyp);
     198:         break;
     199:     case 'b':
     200:         b = *adx++;
     201:         s = (char *)*adx;
     202:         printn((long)b, *s++, flags, ttyp);
     203:         any = 0;
     204:         if (b) {
     205:             while (i = *s++) {
     206:                 if (b & (1 << (i - 1))) {
     207:                     putchar(any? ',' : '<', flags, ttyp);
     208:                     any = 1;
     209:                     for (; (c = *s) > 32; s++)
     210:                         putchar(c, flags, ttyp);
     211:                 } else
     212:                     for (; *s > 32; s++)
     213:                         ;
     214:             }
     215:             if (any)
     216:                 putchar('>', flags, ttyp);
     217:         }
     218:         break;
     219:     case 's':
     220:         s = (char *)*adx;
     221:         while (c = *s++)
     222:             putchar(c, flags, ttyp);
     223:         break;
     224:     case '%':
     225:         putchar(c, flags, ttyp);
     226:         break;
     227:     default:
     228:         putchar('%', flags, ttyp);
     229:         putchar(c, flags, ttyp);
     230:         break;
     231:     }
     232:     adx++;
     233:     goto loop;
     234: }
     235:
     236: /*
     237:  * Printn prints a number n in base b.
     238:  * We don't use recursion to avoid deep kernels stacks.
     239:  */
     240: printn(n, b, flags, ttyp)
     241:     long n;
     242:     u_int b;
     243:     struct tty *ttyp;
     244: {
     245:     char prbuf[12];
     246:     register char *cp = prbuf;
     247:     register int offset = 0;
     248:
     249:     if (n<0)
     250:         switch(b) {
     251:         case 8:     /* unchecked, but should be like hex case */
     252:         case 16:
     253:             offset = b-1;
     254:             n++;
     255:             break;
     256:         case 10:
     257:             putchar('-', flags, ttyp);
     258:             n = -n;
     259:             break;
     260:         }
     261:     do {
     262:         *cp++ = "0123456789ABCDEF"[offset + n%b];
     263:     } while (n = n/b);  /* Avoid  n /= b, since that requires alrem */
     264:     do
     265:         putchar(*--cp, flags, ttyp);
     266:     while (cp > prbuf);
     267: }
     268:
     269: /*
     270:  * Panic is called on unresolvable fatal errors.
     271:  * It prints "panic: mesg", and then reboots.
     272:  * If we are called twice, then we avoid trying to
     273:  * sync the disks as this often leads to recursive panics.
     274:  */
     275: panic(s)
     276:     char *s;
     277: {
     278:     int bootopt = RB_AUTOBOOT|RB_DUMP;
     279:
     280:     if (panicstr)
     281:         bootopt |= RB_NOSYNC;
     282:     else {
     283:         panicstr = s;
     284:     }
     285:     printf("panic: %s\n", s);
     286:     boot(rootdev, bootopt);
     287: }
     288:
     289: /*
     290:  * Warn that a system table is full.
     291:  */
     292: tablefull(tab)
     293:     char *tab;
     294: {
     295:     log(LOG_ERR, "%s: table full\n", tab);
     296: }
     297:
     298: /*
     299:  * Hard error is the preface to plaintive error messages
     300:  * about failing disk tranfers.
     301:  */
     302: harderr(bp, cp)
     303:     struct buf *bp;
     304:     char *cp;
     305: {
     306:     printf("%s%d%c: hard error sn%D ", cp,
     307:         minor(bp->b_dev) >> 3, 'a'+(minor(bp->b_dev) & 07), bp->b_blkno);
     308: }
     309:
     310: /*
     311:  * Print a character on console or users terminal.
     312:  * If destination is console then the last MSGBUFS characters
     313:  * are saved in msgbuf for inspection later.
     314:  */
     315: putchar(c, flags, tp)
     316:     int c, flags;
     317:     register struct tty *tp;
     318: {
     319:
     320:     if (flags & TOTTY) {
     321:         register int s = spltty();
     322:
     323:         if (tp && (tp->t_state & (TS_CARR_ON | TS_ISOPEN)) ==
     324:             (TS_CARR_ON | TS_ISOPEN)) {
     325:             if (c == '\n')
     326:                 (void) ttyoutput('\r', tp);
     327:             (void) ttyoutput(c, tp);
     328:             ttstart(tp);
     329:         }
     330:         splx(s);
     331:     }
     332:     if ((flags & TOLOG) && c != '\0' && c != '\r' && c != 0177)
     333:         logwrt(&c, 1, logMSG);
     334:     if ((flags & TOCONS) && c != '\0')
     335:         cnputc(c);
     336: }

#### Defined functions

harderr defined in line 302; used 11 times

- in /usr/src/sys/pdpuba/br.c line 348
- in /usr/src/sys/pdpuba/hk.c line 586
- in /usr/src/sys/pdpuba/ra.c line 749, 1149
- in /usr/src/sys/pdpuba/rk.c line 171
- in /usr/src/sys/pdpuba/rl.c line 427, 437
- in /usr/src/sys/pdpuba/rx.c line 242
- in /usr/src/sys/pdpuba/si.c line 356, 390
- in /usr/src/sys/pdpuba/xp.c line 735

log defined in line 113; used 66 times

- in line 295
- in /usr/src/sys/pdp/machdep.c line 333
- in /usr/src/sys/pdpuba/br.c line 337
- in /usr/src/sys/pdpuba/dh.c line 208, 451
- in /usr/src/sys/pdpuba/dhu.c line 208, 274, 497
- in /usr/src/sys/pdpuba/dhv.c line 213, 284, 536
- in /usr/src/sys/pdpuba/dz.c line 246
- in /usr/src/sys/pdpuba/hk.c line 316, 509, 581, 587, 825
- in /usr/src/sys/pdpuba/ra.c line 399, 585, 846, 875, 883, 1050, 1150, 1180, 1234
- in /usr/src/sys/pdpuba/rk.c line 172
- in /usr/src/sys/pdpuba/rl.c line 310, 428, 438, 684, 757
- in /usr/src/sys/pdpuba/tm.c line 580
- in /usr/src/sys/pdpuba/tmscp.c line 424, 444, 471, 512, 551, 565, 652, 779, 1007, 1026, 1106, 1131, 1160, 1213, 1297, 1325, 1643, 1748, 1866, 1908, 1944, 1950, 1975, 2006
- in /usr/src/sys/pdpuba/xp.c line 369, 474, 709, 736, 850, 900, 906
- in /usr/src/sys/sys/kern_descrip.c line 502
- in /usr/src/sys/sys/ufs_disksubr.c line 251

logpri defined in line 127; used 2 times

- in line 98, 119

panic defined in line 275; used 137 times

- in /usr/src/sys/h/mbuf.h line 105, 153
- in /usr/src/sys/net/raw_usrreq.c line 309
- in /usr/src/sys/net/route.c line 100
- in /usr/src/sys/netinet/if_ether.c line 209
- in /usr/src/sys/netinet/in.c line 226
- in /usr/src/sys/netinet/ip_icmp.c line 92, 115
- in /usr/src/sys/netinet/ip_input.c line 70
- in /usr/src/sys/netinet/tcp_input.c line 1236
- in /usr/src/sys/netinet/tcp_output.c line 243, 429
- in /usr/src/sys/netinet/tcp_usrreq.c line 312
- in /usr/src/sys/netinet/udp_usrreq.c line 405
- in /usr/src/sys/netns/idp_usrreq.c line 52, 512
- in /usr/src/sys/netns/ns_error.c line 123
- in /usr/src/sys/netns/spp_usrreq.c line 69, 1049, 1407
- in /usr/src/sys/pdp/clock.c line 39
- in /usr/src/sys/pdp/machdep.c line 436
- in /usr/src/sys/pdp/machdep2.c line 83, 142, 169, 187, 195, 209, 216-221(2), 289, 329
- in /usr/src/sys/pdp/mch_xxx.s line 388, 436
- in /usr/src/sys/pdp/mem.c line 40
- in /usr/src/sys/pdp/ram.c line 90
- in /usr/src/sys/pdp/scb.s line 103, 258, 312
- in /usr/src/sys/pdp/trap.c line 120, 247, 276, 356
- in /usr/src/sys/pdpif/if_acc.c line 118
- in /usr/src/sys/pdpif/if_css.c line 140
- in /usr/src/sys/pdpif/if_de.c line 403
- in /usr/src/sys/pdpif/if_ec.c line 347
- in /usr/src/sys/pdpif/if_qe.c line 455, 542
- in /usr/src/sys/pdpif/if_sri.c line 132
- in /usr/src/sys/pdpif/if_uba.c line 195
- in /usr/src/sys/pdpif/if_vv.c line 451
- in /usr/src/sys/pdpuba/tm.c line 553
- in /usr/src/sys/pdpuba/ts.c line 559
- in /usr/src/sys/sys/init_main.c line 171, 184, 194
- in /usr/src/sys/sys/kern_clock.c line 275
- in /usr/src/sys/sys/kern_exec.c line 337
- in /usr/src/sys/sys/kern_exit.c line 99, 118
- in /usr/src/sys/sys/kern_fork.c line 151, 300
- in /usr/src/sys/sys/kern_sig.c line 574
- in /usr/src/sys/sys/kern_subr.c line 97, 141
- in /usr/src/sys/sys/kern_synch.c line 137, 303, 354, 419, 456, 507, 535
- in /usr/src/sys/sys/quota_kern.c line 267, 522, 573, 632, 798
- in /usr/src/sys/sys/quota_sys.c line 187, 306, 354
- in /usr/src/sys/sys/quota_ufs.c line 48
- in /usr/src/sys/sys/subr_rmap.c line 57, 116, 139, 152, 166
- in /usr/src/sys/sys/sys_kern.c line 25
- in /usr/src/sys/sys/sys_pipe.c line 281
- in /usr/src/sys/sys/tty.c line 1559
- in /usr/src/sys/sys/ufs_alloc.c line 186
- in /usr/src/sys/sys/ufs_bio.c line 247, 337, 375
- in /usr/src/sys/sys/ufs_inode.c line 142, 166, 303, 568-571(2)
- in /usr/src/sys/sys/ufs_namei.c line 298, 728, 911, 978-982(2)
- in /usr/src/sys/sys/ufs_syscalls.c line 991, 1020, 1104, 1192
- in /usr/src/sys/sys/ufs_syscalls2.c line 137
- in /usr/src/sys/sys/uipc_mbuf.c line 197, 239-242(2), 253
- in /usr/src/sys/sys/uipc_socket.c line 125, 176, 203, 492-496(2), 518, 542
- in /usr/src/sys/sys/uipc_socket2.c line 77, 501, 567-571(2), 588
- in /usr/src/sys/sys/uipc_syscalls.c line 166
- in /usr/src/sys/sys/uipc_usrreq.c line 116, 139, 192, 215, 257, 344, 409, 431, 510
- in /usr/src/sys/sys/vm_swap.c line 107
- in /usr/src/sys/sys/vm_swp.c line 62

prf defined in line 136; used 5 times

- in line 56, 80, 103, 120-123(2)

printf defined in line 52; used 296 times

- in line 285, 306
- in /usr/src/sys/net/if_loop.c line 121
- in /usr/src/sys/net/if_sl.c line 210, 379
- in /usr/src/sys/netimp/if_imp.c line 102, 400-402(3), 496, 673-687(8)
- in /usr/src/sys/netimp/if_imphost.c line 219
- in /usr/src/sys/netinet/if_ether.c line 315-320(2)
- in /usr/src/sys/netinet/ip_icmp.c line 64, 156, 184, 226, 307, 436
- in /usr/src/sys/netinet/ip_input.c line 751, 866, 945
- in /usr/src/sys/netinet/tcp_debug.c line 83-86(3), 105-135(11)
- in /usr/src/sys/netinet/tcp_input.c line 225, 238
- in /usr/src/sys/netns/ns_error.c line 90, 150, 177-179(2), 198, 239
- in /usr/src/sys/netns/ns_input.c line 301-305(3)
- in /usr/src/sys/netns/ns_ip.c line 233
- in /usr/src/sys/netns/spp_debug.c line 81-84(3), 104, 111-119(3), 126, 132-145(7)
- in /usr/src/sys/netns/spp_usrreq.c line 1626
- in /usr/src/sys/pdp/clock.c line 20
- in /usr/src/sys/pdp/genassym.c line 34-35(2), 41-42(2), 48-57(10), 63-64(2), 70, 76-105(27)
- in /usr/src/sys/pdp/in_cksum.c line 38, 70, 81
- in /usr/src/sys/pdp/machdep.c line 61, 346, 449, 488
- in /usr/src/sys/pdp/machdep2.c line 74, 172, 304, 392, 409-417(3), 445-462(6)
- in /usr/src/sys/pdp/mch_xxx.s line 384, 432
- in /usr/src/sys/pdp/ram.c line 48, 67
- in /usr/src/sys/pdp/trap.c line 114-118(3), 236-240(3), 272-274(3), 290-294(2)
- in /usr/src/sys/pdpif/if_acc.c line 143, 165, 178, 230, 290, 297, 330, 352
- in /usr/src/sys/pdpif/if_css.c line 165, 185, 199, 308, 316, 346, 364
- in /usr/src/sys/pdpif/if_de.c line 187, 195-198(2), 208, 241, 285, 425, 454-459(2), 467-471(2), 505, 524, 544, 582, 715, 735, 831, 887, 934, 944, 1080, 1087, 1149, 1249, 1265, 1272, 1279-1284(2), 1368-1372(2)
- in /usr/src/sys/pdpif/if_dmc.c line 157, 302, 345-353(3), 372
- in /usr/src/sys/pdpif/if_ec.c line 145, 242, 276, 362, 399, 538, 806, 855
- in /usr/src/sys/pdpif/if_en.c line 134, 277, 453
- in /usr/src/sys/pdpif/if_il.c line 173-177(2), 196, 225, 290, 396, 608
- in /usr/src/sys/pdpif/if_qe.c line 280, 621, 889, 941
- in /usr/src/sys/pdpif/if_qt.c line 262, 280, 398, 450, 509, 545, 556-557(2), 580, 647, 844
- in /usr/src/sys/pdpif/if_sri.c line 155, 176, 190, 301, 308, 365, 386, 432-442(4)
- in /usr/src/sys/pdpif/if_vv.c line 224, 250, 263, 326, 382, 450, 811, 928
- in /usr/src/sys/pdpuba/dr.c line 183-186(3), 300
- in /usr/src/sys/pdpuba/ht.c line 320
- in /usr/src/sys/pdpuba/rx.c line 243, 267
- in /usr/src/sys/pdpuba/si.c line 357, 391
- in /usr/src/sys/pdpuba/tmscpdump.c line 140, 153
- in /usr/src/sys/pdpuba/ts.c line 154, 640
- in /usr/src/sys/sys/init_main.c line 214, 230-237(5), 354-358(2), 364-373(3), 406
- in /usr/src/sys/sys/kern_sig.c line 482, 523
- in /usr/src/sys/sys/subr_rmap.c line 88, 183, 236
- in /usr/src/sys/sys/ufs_alloc.c line 251, 314
- in /usr/src/sys/sys/ufs_namei.c line 853, 1201
- in /usr/src/sys/sys/ufs_subr.c line 112, 145
- in /usr/src/sys/sys/ufs_syscalls.c line 1039
- in /usr/src/sys/sys/ufs_syscalls2.c line 136
- in /usr/src/sys/sys/uipc_usrreq.c line 498, 530

printn defined in line 240; used 4 times

- in line 132, 182, 194, 202

putchar defined in line 315; used 18 times

- in line 131-133(2), 151, 169-171(3), 197, 207-210(2), 216, 222-229(4), 257, 265
- in /usr/src/sys/sys/sys_net.c line 504-509(2)

tablefull defined in line 292; used 6 times

- in /usr/src/sys/sys/kern_descrip.c line 312
- in /usr/src/sys/sys/kern_fork.c line 67
- in /usr/src/sys/sys/quota_kern.c line 223, 513
- in /usr/src/sys/sys/ufs_inode.c line 161
- in /usr/src/sys/sys/vm_text.c line 185

tprintf defined in line 90; used 8 times

- in /usr/src/sys/pdpuba/ts.c line 501-503(2), 509-517(5)
- in /usr/src/sys/sys/vm_swp.c line 78

uprintf defined in line 70; used 23 times

- in /usr/src/sys/pdpuba/ht.c line 96-105(3)
- in /usr/src/sys/pdpuba/rk.c line 168
- in /usr/src/sys/pdpuba/tm.c line 149-157(3), 519
- in /usr/src/sys/pdpuba/ts.c line 161-166(2)
- in /usr/src/sys/sys/quota_subr.c line 90, 97, 109, 116
- in /usr/src/sys/sys/quota_ufs.c line 113, 141, 152, 159, 225, 235, 243
- in /usr/src/sys/sys/ufs_alloc.c line 113, 230

#### Defined variables

panicstr defined in line 30; used 2 times

- in line 280-283(2)

#### Defined macros

TOCONS defined in line 21; used 3 times

- in line 56, 123, 334

TOLOG defined in line 23; used 8 times

- in line 56, 95, 102, 120, 131-133(3), 332

TOTTY defined in line 22; used 3 times

- in line 80, 95, 320

Last modified: 1998-12-06 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1095 |