1 /* subr_prf.c 4.9 02/15/81 */ 2 3 #include "../h/param.h" 4 #include "../h/systm.h" 5 #include "../h/seg.h" 6 #include "../h/buf.h" 7 #include "../h/conf.h" 8 #include "../h/mtpr.h" 9 #include "../h/reboot.h" 10 #include "../h/vm.h" 11 #include "../h/msgbuf.h" 12 #include "../h/dir.h" 13 #include "../h/user.h" 14 #include "../h/tty.h" 15 16 /* 17 * In case console is off, 18 * panicstr contains argument to last 19 * call to panic. 20 */ 21 22 char *panicstr; 23 24 /* 25 * Scaled down version of C Library printf. 26 * Only %s %u %d (==%u) %o %x %D are recognized. 27 * Used to print diagnostic information 28 * directly on console tty. 29 * Since it is not interrupt driven, 30 * all system activities are pretty much 31 * suspended. 32 * Printf should not be used for chit-chat. 33 */ 34 /*VARARGS1*/ 35 printf(fmt, x1) 36 register char *fmt; 37 unsigned x1; 38 { 39 40 prf(fmt, &x1, 0); 41 } 42 43 /* 44 * print to the current users terminal, 45 * guarantee not to sleep (so can be called by intr routine) 46 * no watermark checking - so no verbose messages 47 */ 48 /*VARARGS1*/ 49 uprintf(fmt, x1) 50 char *fmt; 51 unsigned x1; 52 { 53 54 prf(fmt, &x1, 2); 55 } 56 57 /* THIS CODE IS VAX DEPENDENT */ 58 prf(fmt, adx, touser) 59 register char *fmt; 60 register u_int *adx; 61 { 62 register int b, c, i; 63 char *s; 64 65 loop: 66 while ((c = *fmt++) != '%') { 67 if(c == '\0') 68 return; 69 putchar(c, touser); 70 } 71 again: 72 c = *fmt++; 73 switch (c) { 74 75 case 'l': 76 goto again; 77 case 'x': case 'X': 78 b = 16; 79 goto number; 80 case 'd': case 'D': 81 case 'u': /* what a joke */ 82 b = 10; 83 goto number; 84 case 'o': case 'O': 85 b = 8; 86 number: 87 printn(*adx, b, touser); 88 break; 89 case 'c': 90 b = *adx; 91 for (i = 24; i >= 0; i -= 8) 92 if (c = (b >> i) & 0x7f) 93 putchar(c, touser); 94 break; 95 case 's': 96 s = (char *)*adx; 97 while (c = *s++) 98 putchar(c, touser); 99 break; 100 } 101 adx++; 102 goto loop; 103 } 104 /* END VAX DEPENDENT CODE */ 105 106 printn(n, b, touser) 107 unsigned long n; 108 { 109 char prbuf[11]; 110 register char *cp; 111 112 if (b == 10 && (int)n < 0) { 113 putchar('-', touser); 114 n = (unsigned)(-(int)n); 115 } 116 cp = prbuf; 117 do { 118 *cp++ = "0123456789abcdef"[n%b]; 119 n /= b; 120 } while (n); 121 do 122 putchar(*--cp, touser); 123 while (cp > prbuf); 124 } 125 126 /* 127 * Panic is called on unresolvable fatal errors. 128 * It syncs, prints "panic: mesg", and then reboots. 129 */ 130 panic(s) 131 char *s; 132 { 133 134 panicstr = s; 135 printf("panic: %s\n", s); 136 (void) spl0(); 137 for(;;) 138 boot(RB_PANIC, RB_AUTOBOOT); 139 } 140 141 /* 142 * prdev prints a warning message of the 143 * form "mesg on dev x/y". 144 * x and y are the major and minor parts of 145 * the device argument. 146 */ 147 prdev(str, dev) 148 char *str; 149 dev_t dev; 150 { 151 152 printf("%s on dev %d/%d\n", str, major(dev), minor(dev)); 153 } 154 155 /* 156 * deverr prints a diagnostic from 157 * a device driver. 158 * It prints the device, block number, 159 * and an octal word (usually some error 160 * status register) passed as argument. 161 */ 162 deverror(bp, o1, o2) 163 register struct buf *bp; 164 { 165 166 printf("bn=%d er=%x,%x", bp->b_blkno, o1,o2); 167 prdev("", bp->b_dev); 168 } 169 170 /* 171 * Print a character on console or users terminal. 172 * If destination is console then the last MSGBUFS characters 173 * are saved in msgbuf for inspection later. 174 */ 175 /*ARGSUSED*/ 176 putchar(c, touser) 177 register int c; 178 { 179 180 if (touser) { 181 register struct tty *tp = u.u_ttyp; 182 183 if (tp && (tp->t_state&CARR_ON)) { 184 register s = spl6(); 185 if (c == '\n') 186 ttyoutput('\r', tp); 187 ttyoutput(c, tp); 188 ttstart(tp); 189 splx(s); 190 } 191 return; 192 } 193 if (c != '\0' && c != '\r' && c != 0177 && mfpr(MAPEN)) { 194 if (msgbuf.msg_magic != MSG_MAGIC) { 195 msgbuf.msg_bufx = 0; 196 msgbuf.msg_magic = MSG_MAGIC; 197 } 198 if (msgbuf.msg_bufx < 0 || msgbuf.msg_bufx >= MSG_BSIZE) 199 msgbuf.msg_bufx = 0; 200 msgbuf.msg_bufc[msgbuf.msg_bufx++] = c; 201 } 202 if (c == 0) 203 return; 204 cnputc(c); 205 } 206