1*2377Swnj /* subr_prf.c 4.7 02/08/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 43*2377Swnj /* 44*2377Swnj * print to the current users terminal, 45*2377Swnj * guarantee not to sleep (so can be called by intr routine) 46*2377Swnj * no watermark checking - so no verbose messages 47*2377Swnj */ 48*2377Swnj /*VARARGS1*/ 49*2377Swnj uprintf(fmt, x1) 50*2377Swnj char *fmt; 51*2377Swnj unsigned x1; 52285Sbill { 53285Sbill 54*2377Swnj prf(fmt, &x1, 2); 55285Sbill } 56285Sbill 57*2377Swnj /* THIS CODE IS VAX DEPENDENT */ 58*2377Swnj prf(fmt, adx, touser) 59285Sbill register char *fmt; 60*2377Swnj register u_int *adx; 61285Sbill { 62*2377Swnj register int b, c; 6331Sbill char *s; 6431Sbill 6531Sbill loop: 66*2377Swnj while ((c = *fmt++) != '%') { 6731Sbill if(c == '\0') 6831Sbill return; 69*2377Swnj putchar(c, touser); 7031Sbill } 71*2377Swnj again: 7231Sbill c = *fmt++; 73*2377Swnj switch (c) { 74*2377Swnj 75*2377Swnj case 'l': 76*2377Swnj goto again; 77*2377Swnj case 'x': case 'X': 78*2377Swnj b = 16; 79*2377Swnj goto number; 80*2377Swnj case 'd': case 'D': 81*2377Swnj case 'u': /* what a joke */ 82*2377Swnj b = 10; 83*2377Swnj goto number; 84*2377Swnj case 'o': case 'O': 85*2377Swnj b = 8; 86*2377Swnj number: 87*2377Swnj printn(*adx, b, touser); 88*2377Swnj break; 89*2377Swnj case 'c': 90*2377Swnj c = *adx; 91*2377Swnj while (c) { 92*2377Swnj putchar(c&0x7f, touser); 93*2377Swnj c >>= 8; 94*2377Swnj } 95*2377Swnj break; 96*2377Swnj case 's': 9731Sbill s = (char *)*adx; 98285Sbill while (c = *s++) 99*2377Swnj putchar(c, touser); 100*2377Swnj break; 10131Sbill } 10231Sbill adx++; 10331Sbill goto loop; 10431Sbill } 105*2377Swnj /* END VAX DEPENDENT CODE */ 10631Sbill 107*2377Swnj printn(n, b, touser) 108*2377Swnj unsigned long n; 10931Sbill { 110*2377Swnj char buf[11]; 111*2377Swnj register char *cp; 11231Sbill 113*2377Swnj if (b == 10 && (int)n < 0) { 114*2377Swnj putchar('-', touser); 115*2377Swnj n = (unsigned)(-(int)n); 11631Sbill } 117*2377Swnj cp = buf; 118*2377Swnj do { 119*2377Swnj *cp++ = "0123456789abcdef"[n%b]; 120*2377Swnj n /= b; 121*2377Swnj } while (n); 122*2377Swnj do 123*2377Swnj putchar(*--cp, touser); 124*2377Swnj while (cp > buf); 12531Sbill } 12631Sbill 12731Sbill /* 1281184Sbill * Panic is called on unresolvable fatal errors. 1291184Sbill * It syncs, prints "panic: mesg", and then reboots. 13031Sbill */ 13131Sbill panic(s) 13231Sbill char *s; 13331Sbill { 134*2377Swnj 13531Sbill panicstr = s; 13631Sbill printf("panic: %s\n", s); 1371787Sbill (void) spl0(); 13831Sbill for(;;) 1391401Sbill boot(RB_PANIC, RB_AUTOBOOT); 14031Sbill } 14131Sbill 14231Sbill /* 14331Sbill * prdev prints a warning message of the 14431Sbill * form "mesg on dev x/y". 14531Sbill * x and y are the major and minor parts of 14631Sbill * the device argument. 14731Sbill */ 14831Sbill prdev(str, dev) 149*2377Swnj char *str; 150*2377Swnj dev_t dev; 15131Sbill { 15231Sbill 153*2377Swnj printf("%s on dev %d/%d\n", str, major(dev), minor(dev)); 15431Sbill } 15531Sbill 15631Sbill /* 15731Sbill * deverr prints a diagnostic from 15831Sbill * a device driver. 15931Sbill * It prints the device, block number, 16031Sbill * and an octal word (usually some error 16131Sbill * status register) passed as argument. 16231Sbill */ 16331Sbill deverror(bp, o1, o2) 164*2377Swnj register struct buf *bp; 16531Sbill { 16631Sbill 1672360Skre printf("bn=%d er=%x,%x", bp->b_blkno, o1,o2); 1682360Skre prdev("", bp->b_dev); 16931Sbill } 170285Sbill 171285Sbill /* 172*2377Swnj * Print a character on console or users terminal. 173285Sbill * If destination is console then the last MSGBUFS characters 174285Sbill * are saved in msgbuf for inspection later. 175285Sbill */ 1761785Sbill /*ARGSUSED*/ 177*2377Swnj putchar(c, touser) 178*2377Swnj register int c; 179285Sbill { 180285Sbill 181*2377Swnj if (touser) { 182*2377Swnj register struct tty *tp = u.u_ttyp; 1832360Skre 184*2377Swnj if (tp && (tp->t_state&CARR_ON)) { 185*2377Swnj register s = spl6(); 186*2377Swnj if (c == '\n') 187*2377Swnj ttyoutput('\r', tp); 1882360Skre ttyoutput(c, tp); 1892360Skre ttstart(tp); 1902360Skre splx(s); 1912360Skre } 1922360Skre return; 1932360Skre } 194285Sbill if (c != '\0' && c != '\r' && c != 0177) { 1952172Swnj if (msgbuf.msg_magic != MSG_MAGIC) { 1962172Swnj msgbuf.msg_bufx = 0; 1972172Swnj msgbuf.msg_magic = MSG_MAGIC; 1982172Swnj } 1992172Swnj if (msgbuf.msg_bufx < 0 || msgbuf.msg_bufx >= MSG_BSIZE) 2002172Swnj msgbuf.msg_bufx = 0; 2012172Swnj msgbuf.msg_bufc[msgbuf.msg_bufx++] = c; 202285Sbill } 203285Sbill if (c == 0) 204285Sbill return; 205285Sbill cnputc(c); 206285Sbill } 207