Subversion Repositories HelenOS

Rev

Rev 264 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 264 Rev 266
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
    */
-
 
58
   
57
   
59
    if (fmath_is_negative(num)) {
58
    if (num<0.0) {
60
        putchar('-');
59
        putchar('-');
-
 
60
        num=num*-1.0;
-
 
61
        }
-
 
62
 
-
 
63
 
-
 
64
    if (fmath_is_infinity(num)) {
-
 
65
        print_str("Inf");
-
 
66
        return;
61
        }
67
        }
62
   
-
 
63
    num=fmath_abs(num);
-
 
64
 
68
 
65
    if ((modifier=='E')||(modifier=='e')) {
69
    if ((modifier=='E')||(modifier=='e')) {
66
        intval2=fmath_fint(fmath_get_decimal_exponent(num),&intval);
70
        intval2=fmath_fint(fmath_get_decimal_exponent(num),&intval);
67
        exponent=intval;
71
        exponent=intval;
68
        if ((intval2<0.0)&&(exponent<0)) exponent--;
72
        if ((intval2<0.0)&&(exponent<0)) exponent--;
69
        num = num / ((fmath_dpow(10.0,exponent)));
73
        num = num / ((fmath_dpow(10.0,exponent)));
70
       
74
       
71
        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
72
        putchar(modifier);
76
        putchar(modifier);
73
        if (exponent<0) {
77
        if (exponent<0) {
74
            putchar('-');
78
            putchar('-');
75
            exponent*=-1;
79
            exponent*=-1;
76
            }
80
            }
77
        print_number(exponent,10);
81
        print_number(exponent,10);
78
        return;
82
        return;
79
        }
83
        }
80
       
84
       
81
 
-
 
82
    /*
-
 
83
    if (fmath_is_infinity(num)) {
-
 
84
        print_str("Inf");
-
 
85
        }
-
 
86
    */
-
 
87
    //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 
88
 
86
 
89
    /* Here is problem with cumulative error while printing big double values -> we will divide
87
    /* Here is problem with cumulative error while printing big double values -> we will divide
90
    the number with a power of 10, print new number with better method for small numbers and then print decimal point at correct position */
88
    the number with a power of 10, print new number with better method for small numbers and then print decimal point at correct position */
91
   
89
   
92
    fmath_fint(fmath_get_decimal_exponent(num),&intval);
90
    fmath_fint(fmath_get_decimal_exponent(num),&intval);
93
   
91
   
94
    exponent=(intval>0.0?intval:0);
92
    exponent=(intval>0.0?intval:0);
95
   
93
   
96
    precision+=exponent;
94
    precision+=exponent;
97
   
95
   
98
    if (exponent>0) num = num / ((fmath_dpow(10.0,exponent)));
96
    if (exponent>0) num = num / ((fmath_dpow(10.0,exponent)));
99
       
97
       
100
    num=fmath_fint(num,&intval);
98
    num=fmath_fint(num,&intval);
101
   
99
   
102
    if (precision>0) {
100
    if (precision>0) {
103
        counter=precision-1;
101
        counter=precision-1;
104
        if (exponent>0) counter++;
102
        if (exponent>0) counter++;
105
       
103
       
106
        if (counter>=DEFAULT_DOUBLE_BUFFER_SIZE) {
104
        if (counter>=DEFAULT_DOUBLE_BUFFER_SIZE) {
107
            counter=DEFAULT_DOUBLE_BUFFER_SIZE;
105
            counter=DEFAULT_DOUBLE_BUFFER_SIZE;
108
        }
106
        }
109
        exponenttmp=exponent;
107
        exponenttmp=exponent;
110
        while(counter>=0) {
108
        while(counter>=0) {
111
            num *= 10.0;
109
            num *= 10.0;
112
            num = fmath_fint(num,&intval2);
110
            num = fmath_fint(num,&intval2);
113
            buf[counter--]=((int)intval2)+'0';
111
            buf[counter--]=((int)intval2)+'0';
114
            exponenttmp--;
112
            exponenttmp--;
115
            if ((exponenttmp==0)&&(counter>=0)) buf[counter--]='.';
113
            if ((exponenttmp==0)&&(counter>=0)) buf[counter--]='.';
116
        }
114
        }
117
        counter=precision;
115
        counter=precision;
118
        if ((exponent==0)&&(counter<DEFAULT_DOUBLE_BUFFER_SIZE)) buf[counter]='.';
116
        if ((exponent==0)&&(counter<DEFAULT_DOUBLE_BUFFER_SIZE)) buf[counter]='.';
119
        counter++; 
117
        counter++; 
120
    } else {
118
    } else {
121
        counter=0; 
119
        counter=0; 
122
    }
120
    }
123
   
121
   
124
    if (intval==0.0) {
122
    if (intval==0.0) {
125
        if (counter<DEFAULT_DOUBLE_BUFFER_SIZE) buf[counter++]='0';
123
        if (counter<DEFAULT_DOUBLE_BUFFER_SIZE) buf[counter++]='0';
126
    } else {
124
    } else {
127
        in1=intval;
125
        in1=intval;
128
        while(( in1>0 )&&(counter<DEFAULT_DOUBLE_BUFFER_SIZE)) {
126
        while(( in1>0 )&&(counter<DEFAULT_DOUBLE_BUFFER_SIZE)) {
129
           
127
           
130
            in2=in1;
128
            in2=in1;
131
            in1/=10;
129
            in1/=10;
132
            buf[counter]=in2-in1*10 + '0';
130
            buf[counter]=in2-in1*10 + '0';
133
            counter++;
131
            counter++;
134
        }
132
        }
135
    }
133
    }
136
   
134
   
137
    counter = (counter>=DEFAULT_DOUBLE_BUFFER_SIZE?DEFAULT_DOUBLE_BUFFER_SIZE:counter);
135
    counter = (counter>=DEFAULT_DOUBLE_BUFFER_SIZE?DEFAULT_DOUBLE_BUFFER_SIZE:counter);
138
    while (counter>0) {
136
    while (counter>0) {
139
        putchar(buf[--counter]);
137
        putchar(buf[--counter]);
140
    };
138
    };
141
    return;
139
    return;
142
}
140
}
143
 
141
 
144
/** Print NULL terminated string
142
/** Print NULL terminated string
145
 *
143
 *
146
 * Print characters from str using putchar() until
144
 * Print characters from str using putchar() until
147
 * \x00 character is reached.
145
 * \x00 character is reached.
148
 *
146
 *
149
 * @param str Characters to print.
147
 * @param str Characters to print.
150
 *
148
 *
151
 */
149
 */
152
void print_str(const char *str)
150
void print_str(const char *str)
153
{
151
{
154
    int i = 0;
152
    int i = 0;
155
    char c;
153
    char c;
156
   
154
   
157
    while (c = str[i++])
155
    while (c = str[i++])
158
        putchar(c);
156
        putchar(c);
159
}
157
}
160
 
158
 
161
 
159
 
162
/** Print hexadecimal digits
160
/** Print hexadecimal digits
163
 *
161
 *
164
 * Print fixed count of hexadecimal digits from
162
 * Print fixed count of hexadecimal digits from
165
 * the number num. The digits are printed in
163
 * the number num. The digits are printed in
166
 * natural left-to-right order starting with
164
 * natural left-to-right order starting with
167
 * the width-th digit.
165
 * the width-th digit.
168
 *
166
 *
169
 * @param num   Number containing digits.
167
 * @param num   Number containing digits.
170
 * @param width Count of digits to print.
168
 * @param width Count of digits to print.
171
 *
169
 *
172
 */
170
 */
173
void print_fixed_hex(const __u64 num, const int width)
171
void print_fixed_hex(const __u64 num, const int width)
174
{
172
{
175
    int i;
173
    int i;
176
   
174
   
177
    for (i = width*8 - 4; i >= 0; i -= 4)
175
    for (i = width*8 - 4; i >= 0; i -= 4)
178
        putchar(digits[(num>>i) & 0xf]);
176
        putchar(digits[(num>>i) & 0xf]);
179
}
177
}
180
 
178
 
181
 
179
 
182
/** Print number in given base
180
/** Print number in given base
183
 *
181
 *
184
 * Print significant digits of a number in given
182
 * Print significant digits of a number in given
185
 * base.
183
 * base.
186
 *
184
 *
187
 * @param num  Number to print.
185
 * @param num  Number to print.
188
 * @param base Base to print the number in (should
186
 * @param base Base to print the number in (should
189
 *             be in range 2 .. 16).
187
 *             be in range 2 .. 16).
190
 *
188
 *
191
 */
189
 */
192
void print_number(const __native num, const unsigned int base)
190
void print_number(const __native num, const unsigned int base)
193
{
191
{
194
    int val = num;
192
    int val = num;
195
    char d[sizeof(__native)*8+1];       /* this is good enough even for base == 2 */
193
    char d[sizeof(__native)*8+1];       /* this is good enough even for base == 2 */
196
    int i = sizeof(__native)*8-1;
194
    int i = sizeof(__native)*8-1;
197
   
195
   
198
    do {
196
    do {
199
        d[i--] = digits[val % base];
197
        d[i--] = digits[val % base];
200
    } while (val /= base);
198
    } while (val /= base);
201
   
199
   
202
    d[sizeof(__native)*8] = 0; 
200
    d[sizeof(__native)*8] = 0; 
203
    print_str(&d[i + 1]);
201
    print_str(&d[i + 1]);
204
}
202
}
205
 
203
 
206
 
204
 
207
/** General formatted text print
205
/** General formatted text print
208
 *
206
 *
209
 * Print text formatted according the fmt parameter
207
 * Print text formatted according the fmt parameter
210
 * and variant arguments. Each formatting directive
208
 * and variant arguments. Each formatting directive
211
 * begins with % (percentage) character and one of the
209
 * begins with % (percentage) character and one of the
212
 * following character:
210
 * following character:
213
 *
211
 *
214
 * %    Prints the percentage character.
212
 * %    Prints the percentage character.
215
 * s    The next variant argument is treated as char*
213
 * s    The next variant argument is treated as char*
216
 *      and printed as a NULL terminated string.
214
 *      and printed as a NULL terminated string.
217
 * c    The next variant argument is treated as a single char.
215
 * c    The next variant argument is treated as a single char.
218
 * p    The next variant argument is treated as a maximum
216
 * p    The next variant argument is treated as a maximum
219
 *      bit-width integer with respect to architecture
217
 *      bit-width integer with respect to architecture
220
 *      and printed in full hexadecimal width.
218
 *      and printed in full hexadecimal width.
221
 * P    As with 'p', but '0x' is prefixed.
219
 * P    As with 'p', but '0x' is prefixed.
222
 * q    The next variant argument is treated as a 64b integer
220
 * q    The next variant argument is treated as a 64b integer
223
 *      and printed in full hexadecimal width.
221
 *      and printed in full hexadecimal width.
224
 * Q    As with 'q', but '0x' is prefixed.
222
 * Q    As with 'q', but '0x' is prefixed.
225
 * l    The next variant argument is treated as a 32b integer
223
 * l    The next variant argument is treated as a 32b integer
226
 *      and printed in full hexadecimal width.
224
 *      and printed in full hexadecimal width.
227
 * L    As with 'l', but '0x' is prefixed.
225
 * L    As with 'l', but '0x' is prefixed.
228
 * w    The next variant argument is treated as a 16b integer
226
 * w    The next variant argument is treated as a 16b integer
229
 *      and printed in full hexadecimal width.
227
 *      and printed in full hexadecimal width.
230
 * W    As with 'w', but '0x' is prefixed.
228
 * W    As with 'w', but '0x' is prefixed.
231
 * b    The next variant argument is treated as a 8b integer
229
 * b    The next variant argument is treated as a 8b integer
232
 *      and printed in full hexadecimal width.
230
 *      and printed in full hexadecimal width.
233
 * N    As with 'b', but '0x' is prefixed.
231
 * N    As with 'b', but '0x' is prefixed.
234
 * d    The next variant argument is treated as integer
232
 * d    The next variant argument is treated as integer
235
 *      and printed in standard decimal format (only significant
233
 *      and printed in standard decimal format (only significant
236
 *      digits).
234
 *      digits).
237
 * x    The next variant argument is treated as integer
235
 * x    The next variant argument is treated as integer
238
 *      and printed in standard hexadecimal format (only significant
236
 *      and printed in standard hexadecimal format (only significant
239
 *      digits).
237
 *      digits).
240
 * X    As with 'x', but '0x' is prefixed.
238
 * X    As with 'x', but '0x' is prefixed.
241
 *
239
 *
242
 * All other characters from fmt except the formatting directives
240
 * All other characters from fmt except the formatting directives
243
 * are printed in verbatim.
241
 * are printed in verbatim.
244
 *
242
 *
245
 * @param fmt Formatting NULL terminated string.
243
 * @param fmt Formatting NULL terminated string.
246
 *
244
 *
247
 */
245
 */
248
void printf(const char *fmt, ...)
246
void printf(const char *fmt, ...)
249
{
247
{
250
    int irqpri, i = 0;
248
    int irqpri, i = 0;
251
    va_list ap;
249
    va_list ap;
252
    char c;
250
    char c;
253
   
251
   
254
    __u16 precision;
252
    __u16 precision;
255
   
253
   
256
    va_start(ap, fmt);
254
    va_start(ap, fmt);
257
 
255
 
258
    irqpri = cpu_priority_high();
256
    irqpri = cpu_priority_high();
259
    spinlock_lock(&printflock);
257
    spinlock_lock(&printflock);
260
 
258
 
261
    while (c = fmt[i++]) {
259
    while (c = fmt[i++]) {
262
        switch (c) {
260
        switch (c) {
263
 
261
 
264
           
262
           
265
           
263
           
266
            /* control character */
264
            /* control character */
267
            case '%':
265
            case '%':
268
           
266
           
269
                precision = DEFAULT_DOUBLE_PRECISION;
267
                precision = DEFAULT_DOUBLE_PRECISION;
270
                if (fmt[i]=='.') {
268
                if (fmt[i]=='.') {
271
                    precision=0;
269
                    precision=0;
272
                    c=fmt[++i];
270
                    c=fmt[++i];
273
                        while((c>='0')&&(c<='9')) {
271
                        while((c>='0')&&(c<='9')) {
274
                            precision = precision*10 + c - '0';
272
                            precision = precision*10 + c - '0';
275
                            c=fmt[++i];
273
                            c=fmt[++i];
276
                            }
274
                            }
277
                       
275
                       
278
                }
276
                }
279
           
277
           
280
                switch (c = fmt[i++]) {
278
                switch (c = fmt[i++]) {
281
 
279
 
282
                /* percentile itself */
280
                /* percentile itself */
283
                case '%':
281
                case '%':
284
                    break;
282
                    break;
285
 
283
 
286
                /*
284
                /*
287
                 * String and character conversions.
285
                 * String and character conversions.
288
                 */
286
                 */
289
                case 's':
287
                case 's':
290
                    print_str(va_arg(ap, char_ptr));
288
                    print_str(va_arg(ap, char_ptr));
291
                    goto loop;
289
                    goto loop;
292
 
290
 
293
                case 'c':
291
                case 'c':
294
                    c = (char) va_arg(ap, int);
292
                    c = (char) va_arg(ap, int);
295
                    break;
293
                    break;
296
 
294
 
297
                /*
295
                /*
298
                         * Hexadecimal conversions with fixed width.
296
                         * Hexadecimal conversions with fixed width.
299
                         */
297
                         */
300
                case 'P':
298
                case 'P':
301
                    print_str("0x");
299
                    print_str("0x");
302
                case 'p':
300
                case 'p':
303
                        print_fixed_hex(va_arg(ap, __native), sizeof(__native));
301
                        print_fixed_hex(va_arg(ap, __native), sizeof(__native));
304
                    goto loop;
302
                    goto loop;
305
 
303
 
306
                case 'Q':
304
                case 'Q':
307
                    print_str("0x");
305
                    print_str("0x");
308
                case 'q':
306
                case 'q':
309
                        print_fixed_hex(va_arg(ap, __u64), INT64);
307
                        print_fixed_hex(va_arg(ap, __u64), INT64);
310
                    goto loop;
308
                    goto loop;
311
 
309
 
312
                case 'L':
310
                case 'L':
313
                    print_str("0x");
311
                    print_str("0x");
314
                case 'l':
312
                case 'l':
315
                        print_fixed_hex(va_arg(ap, __native), INT32);
313
                        print_fixed_hex(va_arg(ap, __native), INT32);
316
                    goto loop;
314
                    goto loop;
317
 
315
 
318
                case 'W':
316
                case 'W':
319
                    print_str("0x");
317
                    print_str("0x");
320
                case 'w':
318
                case 'w':
321
                        print_fixed_hex(va_arg(ap, __native), INT16);
319
                        print_fixed_hex(va_arg(ap, __native), INT16);
322
                    goto loop;
320
                    goto loop;
323
 
321
 
324
                case 'B':
322
                case 'B':
325
                    print_str("0x");
323
                    print_str("0x");
326
                case 'b':
324
                case 'b':
327
                        print_fixed_hex(va_arg(ap, __native), INT8);
325
                        print_fixed_hex(va_arg(ap, __native), INT8);
328
                    goto loop;
326
                    goto loop;
329
 
327
 
330
                /*
328
                /*
331
                         * Floating point conversions.
329
                         * Floating point conversions.
332
                         */
330
                         */
333
               
331
               
334
                case 'F':
332
                case 'F':
335
                        print_double(va_arg(ap, double),'F',precision);
333
                        print_double(va_arg(ap, double),'F',precision);
336
                    goto loop;
334
                    goto loop;
337
                   
335
                   
338
                case 'f':
336
                case 'f':
339
                        print_double(va_arg(ap, double),'f',precision);
337
                        print_double(va_arg(ap, double),'f',precision);
340
                    goto loop;
338
                    goto loop;
341
               
339
               
342
                case 'E':
340
                case 'E':
343
                        print_double(va_arg(ap, double),'E',precision);
341
                        print_double(va_arg(ap, double),'E',precision);
344
                    goto loop;
342
                    goto loop;
345
                case 'e':
343
                case 'e':
346
                        print_double(va_arg(ap, double),'e',precision);
344
                        print_double(va_arg(ap, double),'e',precision);
347
                    goto loop;
345
                    goto loop;
348
               
346
               
349
                /*
347
                /*
350
                         * Decimal and hexadecimal conversions.
348
                         * Decimal and hexadecimal conversions.
351
                         */
349
                         */
352
                case 'd':
350
                case 'd':
353
                        print_number(va_arg(ap, __native), 10);
351
                        print_number(va_arg(ap, __native), 10);
354
                    goto loop;
352
                    goto loop;
355
 
353
 
356
                case 'X':
354
                case 'X':
357
                            print_str("0x");
355
                            print_str("0x");
358
                case 'x':
356
                case 'x':
359
                        print_number(va_arg(ap, __native), 16);
357
                        print_number(va_arg(ap, __native), 16);
360
                    goto loop;
358
                    goto loop;
361
       
359
       
362
                /*
360
                /*
363
                 * Bad formatting.
361
                 * Bad formatting.
364
                 */
362
                 */
365
                default:
363
                default:
366
                    goto out;
364
                    goto out;
367
                }
365
                }
368
 
366
 
369
            default: putchar(c);
367
            default: putchar(c);
370
        }
368
        }
371
   
369
   
372
loop:
370
loop:
373
        ;
371
        ;
374
    }
372
    }
375
 
373
 
376
out:
374
out:
377
    spinlock_unlock(&printflock);
375
    spinlock_unlock(&printflock);
378
    cpu_priority_restore(irqpri);
376
    cpu_priority_restore(irqpri);
379
   
377
   
380
    va_end(ap);
378
    va_end(ap);
381
}
379
}
382
 
380