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