Rev 413 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 413 | Rev 430 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #include <putchar.h> |
29 | #include <putchar.h> |
30 | #include <print.h> |
30 | #include <print.h> |
31 | #include <synch/spinlock.h> |
31 | #include <synch/spinlock.h> |
32 | #include <arch/arg.h> |
32 | #include <arch/arg.h> |
33 | #include <arch/asm.h> |
33 | #include <arch/asm.h> |
34 | #include <arch/fmath.h> |
34 | #include <arch/fmath.h> |
35 | 35 | ||
36 | #include <arch.h> |
36 | #include <arch.h> |
37 | 37 | ||
38 | static char digits[] = "0123456789abcdef"; /**< Hexadecimal characters */ |
38 | static char digits[] = "0123456789abcdef"; /**< Hexadecimal characters */ |
39 | static spinlock_t printflock; /**< printf spinlock */ |
39 | static spinlock_t printflock; /**< printf spinlock */ |
40 | 40 | ||
41 | #define DEFAULT_DOUBLE_PRECISION 16 |
41 | #define DEFAULT_DOUBLE_PRECISION 16 |
42 | #define DEFAULT_DOUBLE_BUFFER_SIZE 128 |
42 | #define DEFAULT_DOUBLE_BUFFER_SIZE 128 |
43 | 43 | ||
44 | void print_double(double num, __u8 modifier, __u16 precision) |
44 | void print_double(double num, __u8 modifier, __u16 precision) |
45 | { |
45 | { |
46 | double intval,intval2; |
46 | double intval,intval2; |
47 | int counter; |
47 | int counter; |
48 | int exponent,exponenttmp; |
48 | int exponent,exponenttmp; |
49 | unsigned char buf[DEFAULT_DOUBLE_BUFFER_SIZE]; |
49 | unsigned char buf[DEFAULT_DOUBLE_BUFFER_SIZE]; |
50 | unsigned long in1,in2; |
50 | unsigned long in1,in2; |
51 | 51 | ||
52 | 52 | ||
53 | if (fmath_is_nan(num)) { |
53 | if (fmath_is_nan(num)) { |
54 | print_str("NaN"); |
54 | print_str("NaN"); |
55 | return; |
55 | return; |
56 | } |
56 | } |
57 | 57 | ||
58 | if (num<0.0) { |
58 | if (num<0.0) { |
59 | putchar('-'); |
59 | putchar('-'); |
60 | num=num*-1.0; |
60 | num=num*-1.0; |
61 | } |
61 | } |
62 | 62 | ||
63 | 63 | ||
64 | if (fmath_is_infinity(num)) { |
64 | if (fmath_is_infinity(num)) { |
65 | print_str("Inf"); |
65 | print_str("Inf"); |
66 | return; |
66 | return; |
67 | } |
67 | } |
68 | 68 | ||
69 | if ((modifier=='E')||(modifier=='e')) { |
69 | if ((modifier=='E')||(modifier=='e')) { |
70 | intval2=fmath_fint(fmath_get_decimal_exponent(num),&intval); |
70 | intval2=fmath_fint(fmath_get_decimal_exponent(num),&intval); |
71 | exponent=intval; |
71 | exponent=intval; |
72 | if ((intval2<0.0)) exponent--; |
72 | if ((intval2<0.0)) exponent--; |
73 | num = num / ((fmath_dpow(10.0,exponent))); |
73 | num = num / ((fmath_dpow(10.0,exponent))); |
74 | 74 | ||
75 | print_double(num,modifier+1,precision); /* modifier+1 = E => F or e => f */ |
75 | print_double(num,modifier+1,precision); /* modifier+1 = E => F or e => f */ |
76 | putchar(modifier); |
76 | putchar(modifier); |
77 | if (exponent<0) { |
77 | if (exponent<0) { |
78 | putchar('-'); |
78 | putchar('-'); |
79 | exponent*=-1; |
79 | exponent*=-1; |
80 | } |
80 | } |
81 | print_number(exponent,10); |
81 | print_number(exponent,10); |
82 | return; |
82 | return; |
83 | } |
83 | } |
84 | 84 | ||
85 | /* TODO: rounding constant - when we got fraction >= 0.5, we must increment last printed number */ |
85 | /* TODO: rounding constant - when we got fraction >= 0.5, we must increment last printed number */ |
86 | 86 | ||
87 | /* |
87 | /* |
88 | * Here is a problem with cumulative error while printing big double values -> we will divide |
88 | * Here is a problem with cumulative error while printing big double values -> we will divide |
89 | * the number with a power of 10, print new number with better method for small numbers and |
89 | * the number with a power of 10, print new number with better method for small numbers and |
90 | * then print decimal point at correct position. |
90 | * then print decimal point at correct position. |
91 | */ |
91 | */ |
92 | 92 | ||
93 | fmath_fint(fmath_get_decimal_exponent(num),&intval); |
93 | fmath_fint(fmath_get_decimal_exponent(num),&intval); |
94 | 94 | ||
95 | exponent=(intval>0.0?intval:0); |
95 | exponent=(intval>0.0?intval:0); |
96 | 96 | ||
97 | precision+=exponent; |
97 | precision+=exponent; |
98 | 98 | ||
99 | if (exponent>0) num = num / ((fmath_dpow(10.0,exponent))); |
99 | if (exponent>0) num = num / ((fmath_dpow(10.0,exponent))); |
100 | 100 | ||
101 | num=fmath_fint(num,&intval); |
101 | num=fmath_fint(num,&intval); |
102 | 102 | ||
103 | if (precision>0) { |
103 | if (precision>0) { |
104 | counter=precision-1; |
104 | counter=precision-1; |
105 | if (exponent>0) counter++; |
105 | if (exponent>0) counter++; |
106 | 106 | ||
107 | if (counter>=DEFAULT_DOUBLE_BUFFER_SIZE) { |
107 | if (counter>=DEFAULT_DOUBLE_BUFFER_SIZE) { |
108 | counter=DEFAULT_DOUBLE_BUFFER_SIZE; |
108 | counter=DEFAULT_DOUBLE_BUFFER_SIZE; |
109 | } |
109 | } |
110 | exponenttmp=exponent; |
110 | exponenttmp=exponent; |
111 | while(counter>=0) { |
111 | while(counter>=0) { |
112 | num *= 10.0; |
112 | num *= 10.0; |
113 | num = fmath_fint(num,&intval2); |
113 | num = fmath_fint(num,&intval2); |
114 | buf[counter--]=((int)intval2)+'0'; |
114 | buf[counter--]=((int)intval2)+'0'; |
115 | exponenttmp--; |
115 | exponenttmp--; |
116 | if ((exponenttmp==0)&&(counter>=0)) buf[counter--]='.'; |
116 | if ((exponenttmp==0)&&(counter>=0)) buf[counter--]='.'; |
117 | } |
117 | } |
118 | counter=precision; |
118 | counter=precision; |
119 | if ((exponent==0)&&(counter<DEFAULT_DOUBLE_BUFFER_SIZE)) buf[counter]='.'; |
119 | if ((exponent==0)&&(counter<DEFAULT_DOUBLE_BUFFER_SIZE)) buf[counter]='.'; |
120 | counter++; |
120 | counter++; |
121 | } else { |
121 | } else { |
122 | counter=0; |
122 | counter=0; |
123 | } |
123 | } |
124 | 124 | ||
125 | in1=intval; |
125 | in1=intval; |
126 | if (in1==0.0) { |
126 | if (in1==0.0) { |
127 | if (counter<DEFAULT_DOUBLE_BUFFER_SIZE) buf[counter++]='0'; |
127 | if (counter<DEFAULT_DOUBLE_BUFFER_SIZE) buf[counter++]='0'; |
128 | } else { |
128 | } else { |
129 | while(( in1>0 )&&(counter<DEFAULT_DOUBLE_BUFFER_SIZE)) { |
129 | while(( in1>0 )&&(counter<DEFAULT_DOUBLE_BUFFER_SIZE)) { |
130 | 130 | ||
131 | in2=in1; |
131 | in2=in1; |
132 | in1/=10; |
132 | in1/=10; |
133 | buf[counter]=in2-in1*10 + '0'; |
133 | buf[counter]=in2-in1*10 + '0'; |
134 | counter++; |
134 | counter++; |
135 | } |
135 | } |
136 | } |
136 | } |
137 | 137 | ||
138 | counter = (counter>=DEFAULT_DOUBLE_BUFFER_SIZE?DEFAULT_DOUBLE_BUFFER_SIZE:counter); |
138 | counter = (counter>=DEFAULT_DOUBLE_BUFFER_SIZE?DEFAULT_DOUBLE_BUFFER_SIZE:counter); |
139 | while (counter>0) { |
139 | while (counter>0) { |
140 | putchar(buf[--counter]); |
140 | putchar(buf[--counter]); |
141 | } |
141 | } |
142 | return; |
142 | return; |
143 | } |
143 | } |
144 | 144 | ||
145 | /** Print NULL terminated string |
145 | /** Print NULL terminated string |
146 | * |
146 | * |
147 | * Print characters from str using putchar() until |
147 | * Print characters from str using putchar() until |
148 | * \\0 character is reached. |
148 | * \\0 character is reached. |
149 | * |
149 | * |
150 | * @param str Characters to print. |
150 | * @param str Characters to print. |
151 | * |
151 | * |
152 | */ |
152 | */ |
153 | void print_str(const char *str) |
153 | void print_str(const char *str) |
154 | { |
154 | { |
155 | int i = 0; |
155 | int i = 0; |
156 | char c; |
156 | char c; |
157 | 157 | ||
158 | while (c = str[i++]) |
158 | while (c = str[i++]) |
159 | putchar(c); |
159 | putchar(c); |
160 | } |
160 | } |
161 | 161 | ||
162 | 162 | ||
163 | /** Print hexadecimal digits |
163 | /** Print hexadecimal digits |
164 | * |
164 | * |
165 | * Print fixed count of hexadecimal digits from |
165 | * Print fixed count of hexadecimal digits from |
166 | * the number num. The digits are printed in |
166 | * the number num. The digits are printed in |
167 | * natural left-to-right order starting with |
167 | * natural left-to-right order starting with |
168 | * the width-th digit. |
168 | * the width-th digit. |
169 | * |
169 | * |
170 | * @param num Number containing digits. |
170 | * @param num Number containing digits. |
171 | * @param width Count of digits to print. |
171 | * @param width Count of digits to print. |
172 | * |
172 | * |
173 | */ |
173 | */ |
174 | void print_fixed_hex(const __u64 num, const int width) |
174 | void print_fixed_hex(const __u64 num, const int width) |
175 | { |
175 | { |
176 | int i; |
176 | int i; |
177 | 177 | ||
178 | for (i = width*8 - 4; i >= 0; i -= 4) |
178 | for (i = width*8 - 4; i >= 0; i -= 4) |
179 | putchar(digits[(num>>i) & 0xf]); |
179 | putchar(digits[(num>>i) & 0xf]); |
180 | } |
180 | } |
181 | 181 | ||
182 | 182 | ||
183 | /** Print number in given base |
183 | /** Print number in given base |
184 | * |
184 | * |
185 | * Print significant digits of a number in given |
185 | * Print significant digits of a number in given |
186 | * base. |
186 | * base. |
187 | * |
187 | * |
188 | * @param num Number to print. |
188 | * @param num Number to print. |
189 | * @param base Base to print the number in (should |
189 | * @param base Base to print the number in (should |
190 | * be in range 2 .. 16). |
190 | * be in range 2 .. 16). |
191 | * |
191 | * |
192 | */ |
192 | */ |
193 | void print_number(const __native num, const unsigned int base) |
193 | void print_number(const __native num, const unsigned int base) |
194 | { |
194 | { |
195 | int val = num; |
195 | int val = num; |
196 | char d[sizeof(__native)*8+1]; /* this is good enough even for base == 2 */ |
196 | char d[sizeof(__native)*8+1]; /* this is good enough even for base == 2 */ |
197 | int i = sizeof(__native)*8-1; |
197 | int i = sizeof(__native)*8-1; |
198 | 198 | ||
199 | do { |
199 | do { |
200 | d[i--] = digits[val % base]; |
200 | d[i--] = digits[val % base]; |
201 | } while (val /= base); |
201 | } while (val /= base); |
202 | 202 | ||
203 | d[sizeof(__native)*8] = 0; |
203 | d[sizeof(__native)*8] = 0; |
204 | print_str(&d[i + 1]); |
204 | print_str(&d[i + 1]); |
205 | } |
205 | } |
206 | 206 | ||
207 | 207 | ||
208 | /** General formatted text print |
208 | /** General formatted text print |
209 | * |
209 | * |
210 | * Print text formatted according the fmt parameter |
210 | * Print text formatted according the fmt parameter |
211 | * and variant arguments. Each formatting directive |
211 | * and variant arguments. Each formatting directive |
212 | * begins with \% (percentage) character and one of the |
212 | * begins with \% (percentage) character and one of the |
213 | * following character: |
213 | * following character: |
214 | * |
214 | * |
215 | * \% Prints the percentage character. |
215 | * \% Prints the percentage character. |
216 | * |
216 | * |
217 | * s The next variant argument is treated as char* |
217 | * s The next variant argument is treated as char* |
218 | * and printed as a NULL terminated string. |
218 | * and printed as a NULL terminated string. |
219 | * |
219 | * |
220 | * c The next variant argument is treated as a single char. |
220 | * c The next variant argument is treated as a single char. |
221 | * |
221 | * |
222 | * p The next variant argument is treated as a maximum |
222 | * p The next variant argument is treated as a maximum |
223 | * bit-width integer with respect to architecture |
223 | * bit-width integer with respect to architecture |
224 | * and printed in full hexadecimal width. |
224 | * and printed in full hexadecimal width. |
225 | * |
225 | * |
226 | * P As with 'p', but '0x' is prefixed. |
226 | * P As with 'p', but '0x' is prefixed. |
227 | * |
227 | * |
228 | * q The next variant argument is treated as a 64b integer |
228 | * q The next variant argument is treated as a 64b integer |
229 | * and printed in full hexadecimal width. |
229 | * and printed in full hexadecimal width. |
230 | * |
230 | * |
231 | * Q As with 'q', but '0x' is prefixed. |
231 | * Q As with 'q', but '0x' is prefixed. |
232 | * |
232 | * |
233 | * l The next variant argument is treated as a 32b integer |
233 | * l The next variant argument is treated as a 32b integer |
234 | * and printed in full hexadecimal width. |
234 | * and printed in full hexadecimal width. |
235 | * |
235 | * |
236 | * L As with 'l', but '0x' is prefixed. |
236 | * L As with 'l', but '0x' is prefixed. |
237 | * |
237 | * |
238 | * w The next variant argument is treated as a 16b integer |
238 | * w The next variant argument is treated as a 16b integer |
239 | * and printed in full hexadecimal width. |
239 | * and printed in full hexadecimal width. |
240 | * |
240 | * |
241 | * W As with 'w', but '0x' is prefixed. |
241 | * W As with 'w', but '0x' is prefixed. |
242 | * |
242 | * |
243 | * b The next variant argument is treated as a 8b integer |
243 | * b The next variant argument is treated as a 8b integer |
244 | * and printed in full hexadecimal width. |
244 | * and printed in full hexadecimal width. |
245 | * |
245 | * |
246 | * B As with 'b', but '0x' is prefixed. |
246 | * B As with 'b', but '0x' is prefixed. |
247 | * |
247 | * |
248 | * d The next variant argument is treated as integer |
248 | * d The next variant argument is treated as integer |
249 | * and printed in standard decimal format (only significant |
249 | * and printed in standard decimal format (only significant |
250 | * digits). |
250 | * digits). |
251 | * |
251 | * |
252 | * x The next variant argument is treated as integer |
252 | * x The next variant argument is treated as integer |
253 | * and printed in standard hexadecimal format (only significant |
253 | * and printed in standard hexadecimal format (only significant |
254 | * digits). |
254 | * digits). |
255 | * |
255 | * |
256 | * X As with 'x', but '0x' is prefixed. |
256 | * X As with 'x', but '0x' is prefixed. |
257 | * |
257 | * |
258 | * . The decimal number following period will be treated as precision |
258 | * . The decimal number following period will be treated as precision |
259 | * for printing floating point numbers. One of 'e', 'E', 'f' or 'F' |
259 | * for printing floating point numbers. One of 'e', 'E', 'f' or 'F' |
260 | * must follow. |
260 | * must follow. |
261 | * |
261 | * |
262 | * e The next variant argument is treated as double precision float |
262 | * e The next variant argument is treated as double precision float |
263 | * and printed in exponent notation with only one digit before decimal point |
263 | * and printed in exponent notation with only one digit before decimal point |
264 | * in specified precision. The exponent sign is printed as 'e'. |
264 | * in specified precision. The exponent sign is printed as 'e'. |
265 | * |
265 | * |
266 | * E As with 'e', but the exponent sign is printed as 'E'. |
266 | * E As with 'e', but the exponent sign is printed as 'E'. |
267 | * |
267 | * |
268 | * f The next variant argument is treated as double precision float |
268 | * f The next variant argument is treated as double precision float |
269 | * and printed in decimal notation in specified precision. |
269 | * and printed in decimal notation in specified precision. |
270 | * |
270 | * |
271 | * F As with 'f'. |
271 | * F As with 'f'. |
272 | * |
272 | * |
273 | * All other characters from fmt except the formatting directives |
273 | * All other characters from fmt except the formatting directives |
274 | * are printed in verbatim. |
274 | * are printed in verbatim. |
275 | * |
275 | * |
276 | * @param fmt Formatting NULL terminated string. |
276 | * @param fmt Formatting NULL terminated string. |
277 | */ |
277 | */ |
278 | void printf(const char *fmt, ...) |
278 | void printf(const char *fmt, ...) |
279 | { |
279 | { |
280 | int irqpri, i = 0; |
280 | int irqpri, i = 0; |
281 | va_list ap; |
281 | va_list ap; |
282 | char c; |
282 | char c; |
283 | 283 | ||
284 | __u16 precision; |
284 | __u16 precision; |
285 | 285 | ||
286 | va_start(ap, fmt); |
286 | va_start(ap, fmt); |
287 | 287 | ||
288 | irqpri = interrupts_disable(); |
288 | irqpri = interrupts_disable(); |
289 | spinlock_lock(&printflock); |
289 | spinlock_lock(&printflock); |
290 | 290 | ||
291 | while (c = fmt[i++]) { |
291 | while (c = fmt[i++]) { |
292 | switch (c) { |
292 | switch (c) { |
293 | 293 | ||
294 | /* control character */ |
294 | /* control character */ |
295 | case '%': |
295 | case '%': |
296 | precision = DEFAULT_DOUBLE_PRECISION; |
296 | precision = DEFAULT_DOUBLE_PRECISION; |
297 | if (fmt[i]=='.') { |
297 | if (fmt[i]=='.') { |
298 | precision=0; |
298 | precision=0; |
299 | c=fmt[++i]; |
299 | c=fmt[++i]; |
300 | while((c>='0')&&(c<='9')) { |
300 | while((c>='0')&&(c<='9')) { |
301 | precision = precision*10 + c - '0'; |
301 | precision = precision*10 + c - '0'; |
302 | c=fmt[++i]; |
302 | c=fmt[++i]; |
303 | } |
303 | } |
304 | } |
304 | } |
305 | 305 | ||
306 | switch (c = fmt[i++]) { |
306 | switch (c = fmt[i++]) { |
307 | 307 | ||
308 | /* percentile itself */ |
308 | /* percentile itself */ |
309 | case '%': |
309 | case '%': |
310 | break; |
310 | break; |
311 | 311 | ||
312 | /* |
312 | /* |
313 | * String and character conversions. |
313 | * String and character conversions. |
314 | */ |
314 | */ |
315 | case 's': |
315 | case 's': |
316 | print_str(va_arg(ap, char_ptr)); |
316 | print_str(va_arg(ap, char_ptr)); |
317 | goto loop; |
317 | goto loop; |
318 | 318 | ||
319 | case 'c': |
319 | case 'c': |
320 | c = (char) va_arg(ap, int); |
320 | c = (char) va_arg(ap, int); |
321 | break; |
321 | break; |
322 | 322 | ||
323 | /* |
323 | /* |
324 | * Hexadecimal conversions with fixed width. |
324 | * Hexadecimal conversions with fixed width. |
325 | */ |
325 | */ |
326 | case 'P': |
326 | case 'P': |
327 | print_str("0x"); |
327 | print_str("0x"); |
328 | case 'p': |
328 | case 'p': |
329 | print_fixed_hex(va_arg(ap, __native), sizeof(__native)); |
329 | print_fixed_hex(va_arg(ap, __native), sizeof(__native)); |
330 | goto loop; |
330 | goto loop; |
331 | 331 | ||
332 | case 'Q': |
332 | case 'Q': |
333 | print_str("0x"); |
333 | print_str("0x"); |
334 | case 'q': |
334 | case 'q': |
335 | print_fixed_hex(va_arg(ap, __u64), INT64); |
335 | print_fixed_hex(va_arg(ap, __u64), INT64); |
336 | goto loop; |
336 | goto loop; |
337 | 337 | ||
338 | case 'L': |
338 | case 'L': |
339 | print_str("0x"); |
339 | print_str("0x"); |
340 | case 'l': |
340 | case 'l': |
341 | print_fixed_hex(va_arg(ap, __native), INT32); |
341 | print_fixed_hex(va_arg(ap, __native), INT32); |
342 | goto loop; |
342 | goto loop; |
343 | 343 | ||
344 | case 'W': |
344 | case 'W': |
345 | print_str("0x"); |
345 | print_str("0x"); |
346 | case 'w': |
346 | case 'w': |
347 | print_fixed_hex(va_arg(ap, __native), INT16); |
347 | print_fixed_hex(va_arg(ap, __native), INT16); |
348 | goto loop; |
348 | goto loop; |
349 | 349 | ||
350 | case 'B': |
350 | case 'B': |
351 | print_str("0x"); |
351 | print_str("0x"); |
352 | case 'b': |
352 | case 'b': |
353 | print_fixed_hex(va_arg(ap, __native), INT8); |
353 | print_fixed_hex(va_arg(ap, __native), INT8); |
354 | goto loop; |
354 | goto loop; |
355 | 355 | ||
356 | /* |
356 | /* |
357 | * Floating point conversions. |
357 | * Floating point conversions. |
358 | */ |
358 | */ |
359 | case 'F': |
359 | case 'F': |
360 | print_double(va_arg(ap, double),'F',precision); |
360 | print_double(va_arg(ap, double),'F',precision); |
361 | goto loop; |
361 | goto loop; |
362 | 362 | ||
363 | case 'f': |
363 | case 'f': |
364 | print_double(va_arg(ap, double),'f',precision); |
364 | print_double(va_arg(ap, double),'f',precision); |
365 | goto loop; |
365 | goto loop; |
366 | 366 | ||
367 | case 'E': |
367 | case 'E': |
368 | print_double(va_arg(ap, double),'E',precision); |
368 | print_double(va_arg(ap, double),'E',precision); |
369 | goto loop; |
369 | goto loop; |
370 | case 'e': |
370 | case 'e': |
371 | print_double(va_arg(ap, double),'e',precision); |
371 | print_double(va_arg(ap, double),'e',precision); |
372 | goto loop; |
372 | goto loop; |
373 | 373 | ||
374 | /* |
374 | /* |
375 | * Decimal and hexadecimal conversions. |
375 | * Decimal and hexadecimal conversions. |
376 | */ |
376 | */ |
377 | case 'd': |
377 | case 'd': |
378 | print_number(va_arg(ap, __native), 10); |
378 | print_number(va_arg(ap, __native), 10); |
379 | goto loop; |
379 | goto loop; |
380 | 380 | ||
381 | case 'X': |
381 | case 'X': |
382 | print_str("0x"); |
382 | print_str("0x"); |
383 | case 'x': |
383 | case 'x': |
384 | print_number(va_arg(ap, __native), 16); |
384 | print_number(va_arg(ap, __native), 16); |
385 | goto loop; |
385 | goto loop; |
386 | 386 | ||
387 | /* |
387 | /* |
388 | * Bad formatting. |
388 | * Bad formatting. |
389 | */ |
389 | */ |
390 | default: |
390 | default: |
391 | goto out; |
391 | goto out; |
392 | } |
392 | } |
393 | 393 | ||
394 | default: putchar(c); |
394 | default: putchar(c); |
395 | } |
395 | } |
396 | 396 | ||
397 | loop: |
397 | loop: |
398 | ; |
398 | ; |
399 | } |
399 | } |
400 | 400 | ||
401 | out: |
401 | out: |
402 | spinlock_unlock(&printflock); |
402 | spinlock_unlock(&printflock); |
403 | interrupts_restore(irqpri); |
403 | interrupts_restore(irqpri); |
404 | 404 | ||
405 | va_end(ap); |
405 | va_end(ap); |
406 | } |
406 | } |
407 | 407 |