Subversion Repositories HelenOS-historic

Rev

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

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