1 /* subr_prf.c 4.8 02/08/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; 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 c = *adx; 91 while (c) { 92 putchar(c&0x7f, touser); 93 c >>= 8; 94 } 95 break; 96 case 's': 97 s = (char *)*adx; 98 while (c = *s++) 99 putchar(c, touser); 100 break; 101 } 102 adx++; 103 goto loop; 104 } 105 /* END VAX DEPENDENT CODE */ 106 107 printn(n, b, touser) 108 unsigned long n; 109 { 110 char buf[11]; 111 register char *cp; 112 113 if (b == 10 && (int)n < 0) { 114 putchar('-', touser); 115 n = (unsigned)(-(int)n); 116 } 117 cp = buf; 118 do { 119 *cp++ = "0123456789abcdef"[n%b]; 120 n /= b; 121 } while (n); 122 do 123 putchar(*--cp, touser); 124 while (cp > buf); 125 } 126 127 /* 128 * Panic is called on unresolvable fatal errors. 129 * It syncs, prints "panic: mesg", and then reboots. 130 */ 131 panic(s) 132 char *s; 133 { 134 135 panicstr = s; 136 printf("panic: %s\n", s); 137 (void) spl0(); 138 for(;;) 139 boot(RB_PANIC, RB_AUTOBOOT); 140 } 141 142 /* 143 * prdev prints a warning message of the 144 * form "mesg on dev x/y". 145 * x and y are the major and minor parts of 146 * the device argument. 147 */ 148 prdev(str, dev) 149 char *str; 150 dev_t dev; 151 { 152 153 printf("%s on dev %d/%d\n", str, major(dev), minor(dev)); 154 } 155 156 /* 157 * deverr prints a diagnostic from 158 * a device driver. 159 * It prints the device, block number, 160 * and an octal word (usually some error 161 * status register) passed as argument. 162 */ 163 deverror(bp, o1, o2) 164 register struct buf *bp; 165 { 166 167 printf("bn=%d er=%x,%x", bp->b_blkno, o1,o2); 168 prdev("", bp->b_dev); 169 } 170 171 /* 172 * Print a character on console or users terminal. 173 * If destination is console then the last MSGBUFS characters 174 * are saved in msgbuf for inspection later. 175 */ 176 /*ARGSUSED*/ 177 putchar(c, touser) 178 register int c; 179 { 180 181 if (touser) { 182 register struct tty *tp = u.u_ttyp; 183 184 if (tp && (tp->t_state&CARR_ON)) { 185 register s = spl6(); 186 if (c == '\n') 187 ttyoutput('\r', tp); 188 ttyoutput(c, tp); 189 ttstart(tp); 190 splx(s); 191 } 192 return; 193 } 194 if (c != '\0' && c != '\r' && c != 0177 && mfpr(MAPEN)) { 195 if (msgbuf.msg_magic != MSG_MAGIC) { 196 msgbuf.msg_bufx = 0; 197 msgbuf.msg_magic = MSG_MAGIC; 198 } 199 if (msgbuf.msg_bufx < 0 || msgbuf.msg_bufx >= MSG_BSIZE) 200 msgbuf.msg_bufx = 0; 201 msgbuf.msg_bufc[msgbuf.msg_bufx++] = c; 202 } 203 if (c == 0) 204 return; 205 cnputc(c); 206 } 207