1*2678Swnj /* subr_prf.c 4.10 02/25/81 */ 231Sbill 331Sbill #include "../h/param.h" 431Sbill #include "../h/systm.h" 531Sbill #include "../h/seg.h" 631Sbill #include "../h/buf.h" 731Sbill #include "../h/conf.h" 8285Sbill #include "../h/mtpr.h" 91184Sbill #include "../h/reboot.h" 102172Swnj #include "../h/vm.h" 112172Swnj #include "../h/msgbuf.h" 122360Skre #include "../h/dir.h" 132360Skre #include "../h/user.h" 142360Skre #include "../h/tty.h" 1531Sbill 1631Sbill /* 1731Sbill * In case console is off, 1831Sbill * panicstr contains argument to last 1931Sbill * call to panic. 2031Sbill */ 2131Sbill 2231Sbill char *panicstr; 2331Sbill 2431Sbill /* 2531Sbill * Scaled down version of C Library printf. 2631Sbill * Only %s %u %d (==%u) %o %x %D are recognized. 2731Sbill * Used to print diagnostic information 2831Sbill * directly on console tty. 2931Sbill * Since it is not interrupt driven, 3031Sbill * all system activities are pretty much 3131Sbill * suspended. 3231Sbill * Printf should not be used for chit-chat. 3331Sbill */ 3431Sbill /*VARARGS1*/ 3531Sbill printf(fmt, x1) 3631Sbill register char *fmt; 3731Sbill unsigned x1; 3831Sbill { 39285Sbill 40285Sbill prf(fmt, &x1, 0); 41285Sbill } 42285Sbill 432377Swnj /* 442377Swnj * print to the current users terminal, 452377Swnj * guarantee not to sleep (so can be called by intr routine) 462377Swnj * no watermark checking - so no verbose messages 472377Swnj */ 482377Swnj /*VARARGS1*/ 492377Swnj uprintf(fmt, x1) 502377Swnj char *fmt; 512377Swnj unsigned x1; 52285Sbill { 53285Sbill 542377Swnj prf(fmt, &x1, 2); 55285Sbill } 56285Sbill 572377Swnj /* THIS CODE IS VAX DEPENDENT */ 582377Swnj prf(fmt, adx, touser) 59285Sbill register char *fmt; 602377Swnj register u_int *adx; 61285Sbill { 622434Swnj register int b, c, i; 6331Sbill char *s; 64*2678Swnj int any; 6531Sbill 6631Sbill loop: 672377Swnj while ((c = *fmt++) != '%') { 6831Sbill if(c == '\0') 6931Sbill return; 702377Swnj putchar(c, touser); 7131Sbill } 722377Swnj again: 7331Sbill c = *fmt++; 742377Swnj switch (c) { 752377Swnj 762377Swnj case 'l': 772377Swnj goto again; 782377Swnj case 'x': case 'X': 792377Swnj b = 16; 802377Swnj goto number; 812377Swnj case 'd': case 'D': 822377Swnj case 'u': /* what a joke */ 832377Swnj b = 10; 842377Swnj goto number; 852377Swnj case 'o': case 'O': 862377Swnj b = 8; 872377Swnj number: 882377Swnj printn(*adx, b, touser); 892377Swnj break; 902377Swnj case 'c': 912434Swnj b = *adx; 922434Swnj for (i = 24; i >= 0; i -= 8) 932434Swnj if (c = (b >> i) & 0x7f) 942434Swnj putchar(c, touser); 952377Swnj break; 96*2678Swnj case 'b': 97*2678Swnj b = *adx++; 98*2678Swnj s = (char *)*adx; 99*2678Swnj printn(b, *s++, touser); 100*2678Swnj any = 0; 101*2678Swnj if (b) { 102*2678Swnj putchar('<', touser); 103*2678Swnj while (i = *s++) { 104*2678Swnj if (b & (1 << (i-1))) { 105*2678Swnj if (any) 106*2678Swnj putchar(',', touser); 107*2678Swnj any = 1; 108*2678Swnj for (; (c = *s) > 32; s++) 109*2678Swnj putchar(c, touser); 110*2678Swnj } else 111*2678Swnj for (; *s > 32; s++) 112*2678Swnj ; 113*2678Swnj } 114*2678Swnj putchar('>', touser); 115*2678Swnj } 116*2678Swnj break; 117*2678Swnj 1182377Swnj case 's': 11931Sbill s = (char *)*adx; 120285Sbill while (c = *s++) 1212377Swnj putchar(c, touser); 1222377Swnj break; 12331Sbill } 12431Sbill adx++; 12531Sbill goto loop; 12631Sbill } 1272377Swnj /* END VAX DEPENDENT CODE */ 12831Sbill 1292377Swnj printn(n, b, touser) 1302377Swnj unsigned long n; 13131Sbill { 1322434Swnj char prbuf[11]; 1332377Swnj register char *cp; 13431Sbill 1352377Swnj if (b == 10 && (int)n < 0) { 1362377Swnj putchar('-', touser); 1372377Swnj n = (unsigned)(-(int)n); 13831Sbill } 1392434Swnj cp = prbuf; 1402377Swnj do { 1412377Swnj *cp++ = "0123456789abcdef"[n%b]; 1422377Swnj n /= b; 1432377Swnj } while (n); 1442377Swnj do 1452377Swnj putchar(*--cp, touser); 1462434Swnj while (cp > prbuf); 14731Sbill } 14831Sbill 14931Sbill /* 1501184Sbill * Panic is called on unresolvable fatal errors. 1511184Sbill * It syncs, prints "panic: mesg", and then reboots. 15231Sbill */ 15331Sbill panic(s) 15431Sbill char *s; 15531Sbill { 1562377Swnj 15731Sbill panicstr = s; 15831Sbill printf("panic: %s\n", s); 1591787Sbill (void) spl0(); 16031Sbill for(;;) 1611401Sbill boot(RB_PANIC, RB_AUTOBOOT); 16231Sbill } 16331Sbill 16431Sbill /* 16531Sbill * prdev prints a warning message of the 16631Sbill * form "mesg on dev x/y". 16731Sbill * x and y are the major and minor parts of 16831Sbill * the device argument. 16931Sbill */ 17031Sbill prdev(str, dev) 1712377Swnj char *str; 1722377Swnj dev_t dev; 17331Sbill { 17431Sbill 1752377Swnj printf("%s on dev %d/%d\n", str, major(dev), minor(dev)); 17631Sbill } 17731Sbill 178*2678Swnj harderr(bp) 179*2678Swnj struct buf *bp; 18031Sbill { 18131Sbill 182*2678Swnj printf("hard err bn %d ", bp->b_blkno); 18331Sbill } 184285Sbill /* 1852377Swnj * Print a character on console or users terminal. 186285Sbill * If destination is console then the last MSGBUFS characters 187285Sbill * are saved in msgbuf for inspection later. 188285Sbill */ 1891785Sbill /*ARGSUSED*/ 1902377Swnj putchar(c, touser) 1912377Swnj register int c; 192285Sbill { 193285Sbill 1942377Swnj if (touser) { 1952377Swnj register struct tty *tp = u.u_ttyp; 1962360Skre 1972377Swnj if (tp && (tp->t_state&CARR_ON)) { 1982377Swnj register s = spl6(); 1992377Swnj if (c == '\n') 2002377Swnj ttyoutput('\r', tp); 2012360Skre ttyoutput(c, tp); 2022360Skre ttstart(tp); 2032360Skre splx(s); 2042360Skre } 2052360Skre return; 2062360Skre } 2072386Swnj if (c != '\0' && c != '\r' && c != 0177 && mfpr(MAPEN)) { 2082172Swnj if (msgbuf.msg_magic != MSG_MAGIC) { 2092172Swnj msgbuf.msg_bufx = 0; 2102172Swnj msgbuf.msg_magic = MSG_MAGIC; 2112172Swnj } 2122172Swnj if (msgbuf.msg_bufx < 0 || msgbuf.msg_bufx >= MSG_BSIZE) 2132172Swnj msgbuf.msg_bufx = 0; 2142172Swnj msgbuf.msg_bufc[msgbuf.msg_bufx++] = c; 215285Sbill } 216285Sbill if (c == 0) 217285Sbill return; 218285Sbill cnputc(c); 219285Sbill } 220