1*31Sbill /* subr_prf.c 3.1 10/14/12 */ 2*31Sbill 3*31Sbill #include "../h/param.h" 4*31Sbill #include "../h/systm.h" 5*31Sbill #include "../h/seg.h" 6*31Sbill #include "../h/buf.h" 7*31Sbill #include "../h/conf.h" 8*31Sbill 9*31Sbill /* 10*31Sbill * In case console is off, 11*31Sbill * panicstr contains argument to last 12*31Sbill * call to panic. 13*31Sbill */ 14*31Sbill 15*31Sbill char *panicstr; 16*31Sbill 17*31Sbill /* 18*31Sbill * Scaled down version of C Library printf. 19*31Sbill * Only %s %u %d (==%u) %o %x %D are recognized. 20*31Sbill * Used to print diagnostic information 21*31Sbill * directly on console tty. 22*31Sbill * Since it is not interrupt driven, 23*31Sbill * all system activities are pretty much 24*31Sbill * suspended. 25*31Sbill * Printf should not be used for chit-chat. 26*31Sbill */ 27*31Sbill /*VARARGS1*/ 28*31Sbill printf(fmt, x1) 29*31Sbill register char *fmt; 30*31Sbill unsigned x1; 31*31Sbill { 32*31Sbill register c; 33*31Sbill register unsigned int *adx; 34*31Sbill char *s; 35*31Sbill 36*31Sbill adx = &x1; 37*31Sbill loop: 38*31Sbill while((c = *fmt++) != '%') { 39*31Sbill if(c == '\0') 40*31Sbill return; 41*31Sbill putchar(c); 42*31Sbill } 43*31Sbill c = *fmt++; 44*31Sbill if(c == 'X') 45*31Sbill printx((long)*adx); 46*31Sbill else if(c == 'd' || c == 'u' || c == 'o' || c == 'x') 47*31Sbill printn((long)*adx, c=='o'? 8: (c=='x'? 16:10)); 48*31Sbill else if(c == 's') { 49*31Sbill s = (char *)*adx; 50*31Sbill while(c = *s++) 51*31Sbill putchar(c); 52*31Sbill } else if (c == 'D') { 53*31Sbill printn(*(long *)adx, 10); 54*31Sbill adx += (sizeof(long) / sizeof(int)) - 1; 55*31Sbill } 56*31Sbill adx++; 57*31Sbill goto loop; 58*31Sbill } 59*31Sbill 60*31Sbill printx(x) 61*31Sbill long x; 62*31Sbill { 63*31Sbill int i; 64*31Sbill 65*31Sbill for (i = 0; i < 8; i++) 66*31Sbill putchar("0123456789ABCDEF"[(x>>((7-i)*4))&0xf]); 67*31Sbill } 68*31Sbill 69*31Sbill /* 70*31Sbill * Print an unsigned integer in base b. 71*31Sbill */ 72*31Sbill printn(n, b) 73*31Sbill long n; 74*31Sbill { 75*31Sbill register long a; 76*31Sbill 77*31Sbill if (n<0) { /* shouldn't happen */ 78*31Sbill putchar('-'); 79*31Sbill n = -n; 80*31Sbill } 81*31Sbill if(a = n/b) 82*31Sbill printn(a, b); 83*31Sbill putchar("0123456789ABCDEF"[(int)(n%b)]); 84*31Sbill } 85*31Sbill 86*31Sbill /* 87*31Sbill * Panic is called on unresolvable 88*31Sbill * fatal errors. 89*31Sbill * It syncs, prints "panic: mesg" and 90*31Sbill * then loops. 91*31Sbill */ 92*31Sbill panic(s) 93*31Sbill char *s; 94*31Sbill { 95*31Sbill panicstr = s; 96*31Sbill update(); 97*31Sbill printf("panic: %s\n", s); 98*31Sbill spl0(); 99*31Sbill for(;;) 100*31Sbill ; 101*31Sbill } 102*31Sbill 103*31Sbill /* 104*31Sbill * prdev prints a warning message of the 105*31Sbill * form "mesg on dev x/y". 106*31Sbill * x and y are the major and minor parts of 107*31Sbill * the device argument. 108*31Sbill */ 109*31Sbill prdev(str, dev) 110*31Sbill char *str; 111*31Sbill dev_t dev; 112*31Sbill { 113*31Sbill 114*31Sbill printf("%s on dev %u/%u\n", str, major(dev), minor(dev)); 115*31Sbill } 116*31Sbill 117*31Sbill /* 118*31Sbill * deverr prints a diagnostic from 119*31Sbill * a device driver. 120*31Sbill * It prints the device, block number, 121*31Sbill * and an octal word (usually some error 122*31Sbill * status register) passed as argument. 123*31Sbill */ 124*31Sbill deverror(bp, o1, o2) 125*31Sbill register struct buf *bp; 126*31Sbill { 127*31Sbill 128*31Sbill prdev("err", bp->b_dev); 129*31Sbill printf("bn=%d er=%x,%x\n", bp->b_blkno, o1,o2); 130*31Sbill } 131