sys/prf.c

02650 #include "../h/param.h" 02651 #include "../h/systm.h" 02652 #include "../h/seg.h" 02653 #include "../h/buf.h" 02654 #include "../h/conf.h" 02655 02656 /* 02657 * In case console is off, 02658 * panicstr contains argument to last 02659 * call to panic. 02660 */ 02661 02662 char *panicstr; 02663 02664 /* 02665 * Scaled down version of C Library printf. 02666 * Only %s %u %d (==%u) %o %x %D are recognized. 02667 * Used to print diagnostic information 02668 * directly on console tty. 02669 * Since it is not interrupt driven, 02670 * all system activities are pretty much 02671 * suspended. 02672 * Printf should not be used for chit-chat. 02673 */ 02674 /* VARARGS 1 */ 02675 printf(fmt, x1) 02676 register char *fmt; 02677 unsigned x1; 02678 { 02679 register c; 02680 register unsigned int *adx; 02681 char *s; 02682 02683 adx = &x1; 02684 loop: 02685 while((c = *fmt++) != '%') { 02686 if(c == '\0') 02687 return; 02688 putchar(c); 02689 } 02690 c = *fmt++; 02691 if(c == 'd' || c == 'u' || c == 'o' || c == 'x') 02692 printn((long)*adx, c=='o'? 8: (c=='x'? 16:10)); 02693 else if(c == 's') { 02694 s = (char *)*adx; 02695 while(c = *s++) 02696 putchar(c); 02697 } else if (c == 'D') { 02698 printn(*(long *)adx, 10); 02699 adx += (sizeof(long) / sizeof(int)) - 1; 02700 } 02701 adx++; 02702 goto loop; 02703 } 02704 02705 /* 02706 * Print an unsigned integer in base b. 02707 */ 02708 printn(n, b) 02709 long n; 02710 { 02711 register long a; 02712 02713 if (n<0) { /* shouldn't happen */ 02714 putchar('-'); 02715 n = -n; 02716 } 02717 if(a = n/b) 02718 printn(a, b); 02719 putchar("0123456789ABCDEF"[(int)(n%b)]); 02720 } 02721 02722 /* 02723 * Panic is called on unresolvable 02724 * fatal errors. 02725 * It syncs, prints "panic: mesg" and 02726 * then loops. 02727 */ 02728 panic(s) 02729 char *s; 02730 { 02731 panicstr = s; 02732 update(); 02733 printf("panic: %s\n", s); 02734 for(;;) 02735 idle(); 02736 } 02737 02738 /* 02739 * prdev prints a warning message of the 02740 * form "mesg on dev x/y". 02741 * x and y are the major and minor parts of 02742 * the device argument. 02743 */ 02744 prdev(str, dev) 02745 char *str; 02746 dev_t dev; 02747 { 02748 02749 printf("%s on dev %u/%u\n", str, major(dev), minor(dev)); 02750 } 02751 02752 /* 02753 * deverr prints a diagnostic from 02754 * a device driver. 02755 * It prints the device, block number, 02756 * and an octal word (usually some error 02757 * status register) passed as argument. 02758 */ 02759 deverror(bp, o1, o2) 02760 register struct buf *bp; 02761 { 02762 02763 prdev("err", bp->b_dev); 02764 printf("bn=%D er=%o,%o\n", bp->b_blkno, o1, o2); 02765 } 02766 02767 02768 02769 02770 02771 02772 02773 02774 02775 02776 02777 02778 02779 02780 02781 02782 02783 02784 02785 02786 02787 02788 02789 02790 02791 02792 02793 02794 02795 02796 02797 02798 02799