Commit | Line | Data |
---|---|---|
2bb8d359 | 1 | /* subr_prf.c 4.17 81/05/11 */ |
8cbb423c BJ |
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" | |
96d38f03 | 8 | #include "../h/mtpr.h" |
0dc06be8 | 9 | #include "../h/reboot.h" |
90f8d91f BJ |
10 | #include "../h/vm.h" |
11 | #include "../h/msgbuf.h" | |
d11b28dc RE |
12 | #include "../h/dir.h" |
13 | #include "../h/user.h" | |
14 | #include "../h/tty.h" | |
96d38f03 | 15 | |
8cbb423c BJ |
16 | /* |
17 | * In case console is off, | |
18 | * panicstr contains argument to last | |
19 | * call to panic. | |
20 | */ | |
8cbb423c BJ |
21 | char *panicstr; |
22 | ||
23 | /* | |
24 | * Scaled down version of C Library printf. | |
b725a0ca BJ |
25 | * Used to print diagnostic information directly on console tty. |
26 | * Since it is not interrupt driven, all system activities are | |
27 | * suspended. Printf should not be used for chit-chat. | |
28 | * | |
29 | * One additional format: %b is supported to decode error registers. | |
30 | * Usage is: | |
31 | * printf("reg=%b\n", regval, "<base><arg>*"); | |
32 | * Where <base> is the output base expressed as a control character, | |
33 | * e.g. \10 gives octal; \20 gives hex. Each arg is a sequence of | |
34 | * characters, the first of which gives the bit number to be inspected | |
35 | * (origin 1), and the next characters (up to a control character, i.e. | |
36 | * a character <= 32), give the name of the register. Thus | |
37 | * printf("reg=%b\n", 3, "\10\2BITTWO\1BITONE\n"); | |
38 | * would produce output: | |
39 | * reg=2<BITTWO,BITONE> | |
8cbb423c BJ |
40 | */ |
41 | /*VARARGS1*/ | |
42 | printf(fmt, x1) | |
b725a0ca BJ |
43 | char *fmt; |
44 | unsigned x1; | |
96d38f03 BJ |
45 | { |
46 | ||
47 | prf(fmt, &x1, 0); | |
48 | } | |
49 | ||
843267b1 | 50 | /* |
b725a0ca BJ |
51 | * Uprintf prints to the current user's terminal, |
52 | * guarantees not to sleep (so can be called by interrupt routines) | |
53 | * and does no watermark checking - (so no verbose messages). | |
843267b1 BJ |
54 | */ |
55 | /*VARARGS1*/ | |
56 | uprintf(fmt, x1) | |
b725a0ca | 57 | char *fmt; |
843267b1 | 58 | unsigned x1; |
96d38f03 BJ |
59 | { |
60 | ||
843267b1 | 61 | prf(fmt, &x1, 2); |
96d38f03 BJ |
62 | } |
63 | ||
843267b1 | 64 | prf(fmt, adx, touser) |
b725a0ca BJ |
65 | register char *fmt; |
66 | register u_int *adx; | |
8cbb423c | 67 | { |
d5726689 | 68 | register int b, c, i; |
8cbb423c | 69 | char *s; |
3c79e4ff | 70 | int any; |
8cbb423c | 71 | |
8cbb423c | 72 | loop: |
843267b1 | 73 | while ((c = *fmt++) != '%') { |
8cbb423c BJ |
74 | if(c == '\0') |
75 | return; | |
843267b1 | 76 | putchar(c, touser); |
8cbb423c | 77 | } |
843267b1 | 78 | again: |
8cbb423c | 79 | c = *fmt++; |
b725a0ca | 80 | /* THIS CODE IS VAX DEPENDENT IN HANDLING %l? AND %c */ |
843267b1 BJ |
81 | switch (c) { |
82 | ||
83 | case 'l': | |
84 | goto again; | |
85 | case 'x': case 'X': | |
86 | b = 16; | |
87 | goto number; | |
88 | case 'd': case 'D': | |
89 | case 'u': /* what a joke */ | |
90 | b = 10; | |
91 | goto number; | |
92 | case 'o': case 'O': | |
93 | b = 8; | |
94 | number: | |
a0eab615 | 95 | printn((u_long)*adx, b, touser); |
843267b1 BJ |
96 | break; |
97 | case 'c': | |
d5726689 BJ |
98 | b = *adx; |
99 | for (i = 24; i >= 0; i -= 8) | |
100 | if (c = (b >> i) & 0x7f) | |
101 | putchar(c, touser); | |
843267b1 | 102 | break; |
3c79e4ff BJ |
103 | case 'b': |
104 | b = *adx++; | |
105 | s = (char *)*adx; | |
a0eab615 | 106 | printn((u_long)b, *s++, touser); |
3c79e4ff BJ |
107 | any = 0; |
108 | if (b) { | |
109 | putchar('<', touser); | |
110 | while (i = *s++) { | |
111 | if (b & (1 << (i-1))) { | |
112 | if (any) | |
113 | putchar(',', touser); | |
114 | any = 1; | |
115 | for (; (c = *s) > 32; s++) | |
116 | putchar(c, touser); | |
117 | } else | |
118 | for (; *s > 32; s++) | |
119 | ; | |
120 | } | |
121 | putchar('>', touser); | |
122 | } | |
123 | break; | |
124 | ||
843267b1 | 125 | case 's': |
8cbb423c | 126 | s = (char *)*adx; |
96d38f03 | 127 | while (c = *s++) |
843267b1 BJ |
128 | putchar(c, touser); |
129 | break; | |
2bb8d359 BJ |
130 | |
131 | case '%': | |
132 | putchar('%', touser); | |
133 | break; | |
8cbb423c BJ |
134 | } |
135 | adx++; | |
136 | goto loop; | |
137 | } | |
138 | ||
b725a0ca BJ |
139 | /* |
140 | * Printn prints a number n in base b. | |
141 | * We don't use recursion to avoid deep kernel stacks. | |
142 | */ | |
843267b1 | 143 | printn(n, b, touser) |
a0eab615 | 144 | u_long n; |
8cbb423c | 145 | { |
d5726689 | 146 | char prbuf[11]; |
843267b1 | 147 | register char *cp; |
8cbb423c | 148 | |
843267b1 BJ |
149 | if (b == 10 && (int)n < 0) { |
150 | putchar('-', touser); | |
151 | n = (unsigned)(-(int)n); | |
8cbb423c | 152 | } |
d5726689 | 153 | cp = prbuf; |
843267b1 BJ |
154 | do { |
155 | *cp++ = "0123456789abcdef"[n%b]; | |
156 | n /= b; | |
157 | } while (n); | |
158 | do | |
159 | putchar(*--cp, touser); | |
d5726689 | 160 | while (cp > prbuf); |
8cbb423c BJ |
161 | } |
162 | ||
163 | /* | |
0dc06be8 | 164 | * Panic is called on unresolvable fatal errors. |
b725a0ca BJ |
165 | * It prints "panic: mesg", and then reboots. |
166 | * If we are called twice, then we avoid trying to | |
167 | * sync the disks as this often leads to recursive panics. | |
8cbb423c BJ |
168 | */ |
169 | panic(s) | |
b725a0ca | 170 | char *s; |
8cbb423c | 171 | { |
b725a0ca | 172 | int bootopt = panicstr ? RB_AUTOBOOT : RB_AUTOBOOT|RB_NOSYNC; |
843267b1 | 173 | |
8cbb423c | 174 | panicstr = s; |
a9c526c1 | 175 | printf("panic: %s\n", s); |
934e4ecf | 176 | (void) spl0(); |
b725a0ca | 177 | boot(RB_PANIC, bootopt); |
8cbb423c BJ |
178 | } |
179 | ||
fdd11a14 BJ |
180 | /* |
181 | * Warn that a system table is full. | |
182 | */ | |
183 | tablefull(tab) | |
184 | char *tab; | |
185 | { | |
186 | ||
187 | printf("%s: table is full\n", tab); | |
188 | } | |
189 | ||
b725a0ca BJ |
190 | /* |
191 | * Hard error is the preface to plaintive error messages | |
fdd11a14 | 192 | * about failing disk transfers. |
b725a0ca | 193 | */ |
fdd11a14 | 194 | harderr(bp, cp) |
3c79e4ff | 195 | struct buf *bp; |
fdd11a14 | 196 | char *cp; |
8cbb423c BJ |
197 | { |
198 | ||
fdd11a14 BJ |
199 | printf("%s%d%c: hard error sn%d ", cp, |
200 | dkunit(bp), 'a'+(minor(bp->b_dev)&07), bp->b_blkno); | |
8cbb423c | 201 | } |
b725a0ca | 202 | |
96d38f03 | 203 | /* |
843267b1 | 204 | * Print a character on console or users terminal. |
96d38f03 BJ |
205 | * If destination is console then the last MSGBUFS characters |
206 | * are saved in msgbuf for inspection later. | |
207 | */ | |
49c84d3f | 208 | /*ARGSUSED*/ |
843267b1 BJ |
209 | putchar(c, touser) |
210 | register int c; | |
96d38f03 | 211 | { |
96d38f03 | 212 | |
843267b1 BJ |
213 | if (touser) { |
214 | register struct tty *tp = u.u_ttyp; | |
d11b28dc | 215 | |
843267b1 BJ |
216 | if (tp && (tp->t_state&CARR_ON)) { |
217 | register s = spl6(); | |
218 | if (c == '\n') | |
219 | ttyoutput('\r', tp); | |
d11b28dc RE |
220 | ttyoutput(c, tp); |
221 | ttstart(tp); | |
222 | splx(s); | |
223 | } | |
224 | return; | |
225 | } | |
cf19cacc | 226 | if (c != '\0' && c != '\r' && c != 0177 && mfpr(MAPEN)) { |
90f8d91f BJ |
227 | if (msgbuf.msg_magic != MSG_MAGIC) { |
228 | msgbuf.msg_bufx = 0; | |
229 | msgbuf.msg_magic = MSG_MAGIC; | |
230 | } | |
231 | if (msgbuf.msg_bufx < 0 || msgbuf.msg_bufx >= MSG_BSIZE) | |
232 | msgbuf.msg_bufx = 0; | |
233 | msgbuf.msg_bufc[msgbuf.msg_bufx++] = c; | |
96d38f03 BJ |
234 | } |
235 | if (c == 0) | |
236 | return; | |
237 | cnputc(c); | |
238 | } |