Subversion Repositories HelenOS-historic

Rev

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

Rev 1273 Rev 1604
1
/*
1
/*
2
 * Copyright (C) 2001-2004 Jakub Jermar
2
 * Copyright (C) 2001-2004 Jakub Jermar
3
 * Copyright (C) 2006 Josef Cejka
3
 * Copyright (C) 2006 Josef Cejka
4
 * All rights reserved.
4
 * All rights reserved.
5
 *
5
 *
6
 * Redistribution and use in source and binary forms, with or without
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
7
 * modification, are permitted provided that the following conditions
8
 * are met:
8
 * are met:
9
 *
9
 *
10
 * - Redistributions of source code must retain the above copyright
10
 * - Redistributions of source code must retain the above copyright
11
 *   notice, this list of conditions and the following disclaimer.
11
 *   notice, this list of conditions and the following disclaimer.
12
 * - Redistributions in binary form must reproduce the above copyright
12
 * - Redistributions in binary form must reproduce the above copyright
13
 *   notice, this list of conditions and the following disclaimer in the
13
 *   notice, this list of conditions and the following disclaimer in the
14
 *   documentation and/or other materials provided with the distribution.
14
 *   documentation and/or other materials provided with the distribution.
15
 * - The name of the author may not be used to endorse or promote products
15
 * - The name of the author may not be used to endorse or promote products
16
 *   derived from this software without specific prior written permission.
16
 *   derived from this software without specific prior written permission.
17
 *
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
28
 */
29
 
29
 
30
/**
30
/**
31
 * @file    print.c
31
 * @file    print.c
32
 * @brief   Printing functions.
32
 * @brief   Printing functions.
33
 */
33
 */
34
 
34
 
35
#include <printf/printf_core.h>
35
#include <printf/printf_core.h>
36
#include <putchar.h>
36
#include <putchar.h>
37
#include <print.h>
37
#include <print.h>
38
#include <synch/spinlock.h>
38
#include <synch/spinlock.h>
39
#include <arch/arg.h>
39
#include <arch/arg.h>
40
#include <arch/asm.h>
40
#include <arch/asm.h>
41
 
41
 
42
#include <arch.h>
42
#include <arch.h>
43
 
43
 
44
SPINLOCK_INITIALIZE(printflock);            /**< printf spinlock */
44
SPINLOCK_INITIALIZE(printflock);            /**< printf spinlock */
45
 
45
 
46
#define __PRINTF_FLAG_PREFIX        0x00000001  /**< show prefixes 0x or 0*/
46
#define __PRINTF_FLAG_PREFIX        0x00000001  /**< show prefixes 0x or 0*/
47
#define __PRINTF_FLAG_SIGNED        0x00000002  /**< signed / unsigned number */
47
#define __PRINTF_FLAG_SIGNED        0x00000002  /**< signed / unsigned number */
48
#define __PRINTF_FLAG_ZEROPADDED    0x00000004  /**< print leading zeroes */
48
#define __PRINTF_FLAG_ZEROPADDED    0x00000004  /**< print leading zeroes */
49
#define __PRINTF_FLAG_LEFTALIGNED   0x00000010  /**< align to left */
49
#define __PRINTF_FLAG_LEFTALIGNED   0x00000010  /**< align to left */
50
#define __PRINTF_FLAG_SHOWPLUS      0x00000020  /**< always show + sign */
50
#define __PRINTF_FLAG_SHOWPLUS      0x00000020  /**< always show + sign */
51
#define __PRINTF_FLAG_SPACESIGN     0x00000040  /**< print space instead of plus */
51
#define __PRINTF_FLAG_SPACESIGN     0x00000040  /**< print space instead of plus */
52
#define __PRINTF_FLAG_BIGCHARS      0x00000080  /**< show big characters */
52
#define __PRINTF_FLAG_BIGCHARS      0x00000080  /**< show big characters */
53
#define __PRINTF_FLAG_NEGATIVE      0x00000100  /**< number has - sign */
53
#define __PRINTF_FLAG_NEGATIVE      0x00000100  /**< number has - sign */
54
 
54
 
55
#define PRINT_NUMBER_BUFFER_SIZE    (64+5)      /**< Buffer big enought for 64 bit number
55
#define PRINT_NUMBER_BUFFER_SIZE    (64+5)      /**< Buffer big enought for 64 bit number
56
                             * printed in base 2, sign, prefix and
56
                             * printed in base 2, sign, prefix and
57
                             * 0 to terminate string.. (last one is only for better testing
57
                             * 0 to terminate string.. (last one is only for better testing
58
                             * end of buffer by zero-filling subroutine)*/
58
                             * end of buffer by zero-filling subroutine)*/
59
 
59
 
60
/** Enumeration of possible arguments types.
60
/** Enumeration of possible arguments types.
61
 */
61
 */
62
typedef enum {
62
typedef enum {
63
    PrintfQualifierByte = 0,
63
    PrintfQualifierByte = 0,
64
    PrintfQualifierShort,
64
    PrintfQualifierShort,
65
    PrintfQualifierInt,
65
    PrintfQualifierInt,
66
    PrintfQualifierLong,
66
    PrintfQualifierLong,
67
    PrintfQualifierLongLong,
67
    PrintfQualifierLongLong,
68
    PrintfQualifierNative,
68
    PrintfQualifierNative,
69
    PrintfQualifierPointer
69
    PrintfQualifierPointer
70
} qualifier_t;
70
} qualifier_t;
71
 
71
 
72
static char digits_small[] = "0123456789abcdef";    /**< Small hexadecimal characters */
72
static char digits_small[] = "0123456789abcdef";    /**< Small hexadecimal characters */
73
static char digits_big[] = "0123456789ABCDEF";  /**< Big hexadecimal characters */
73
static char digits_big[] = "0123456789ABCDEF";  /**< Big hexadecimal characters */
74
 
74
 
75
/** Checks c for a digit.
75
/** Checks c for a digit.
76
 * @param c One character.
76
 * @param c One character.
77
 * @return nonzero if c is from interval '0 to '9'.
77
 * @return nonzero if c is from interval '0 to '9'.
78
 */
78
 */
79
static inline int isdigit(int c)
79
static inline int isdigit(int c)
80
{
80
{
81
    return ((c >= '0' )&&( c <= '9'));
81
    return ((c >= '0' )&&( c <= '9'));
82
}
82
}
83
 
83
 
84
/** Compute length of given zero terminated string.
84
/** Compute length of given zero terminated string.
85
 * @param str Pointer to valid string.
85
 * @param str Pointer to valid string.
86
 * @return string length without trailing zero.
86
 * @return string length without trailing zero.
87
 */
87
 */
88
static __native strlen(const char *str)
88
static __native strlen(const char *str)
89
{
89
{
90
    __native counter = 0;
90
    __native counter = 0;
91
 
91
 
92
    while (str[counter] != 0) {
92
    while (str[counter] != 0) {
93
        counter++;
93
        counter++;
94
    }
94
    }
95
 
95
 
96
    return counter;
96
    return counter;
97
}
97
}
98
 
98
 
99
/** Print count chars from buffer without adding newline
99
/** Print count chars from buffer without adding newline
100
 * @param buf Buffer with size at least count bytes - NULL pointer NOT allowed!
100
 * @param buf Buffer with size at least count bytes - NULL pointer NOT allowed!
101
 * @param count
101
 * @param count
102
 * @param ps output method and its data
102
 * @param ps output method and its data
103
 * @return 0 on success, EOF on fail
103
 * @return number or printed characters
104
 */
104
 */
105
static int printf_putnchars(const char * buf, size_t count, struct printf_spec *ps)
105
static int printf_putnchars(const char * buf, size_t count, struct printf_spec *ps)
106
{
106
{
107
    if (ps->write((void *)buf, count, ps->data) == count) {
107
    return ps->write((void *)buf, count, ps->data);
108
        return 0;
-
 
109
    }
-
 
110
   
-
 
111
    return EOF;
-
 
112
}
108
}
113
 
109
 
114
/** Print string without added newline
110
/** Print string without added newline
115
 * @param str string to print
111
 * @param str string to print
116
 * @param ps write function specification and support data
112
 * @param ps write function specification and support data
117
 * @return 0 on success or EOF on fail
113
 * @return number or printed characters
118
 */
114
 */
119
static int printf_putstr(const char * str, struct printf_spec *ps)
115
static int printf_putstr(const char * str, struct printf_spec *ps)
120
{
116
{
121
    size_t count;
117
    size_t count;
122
   
118
   
123
    if (str == NULL) {
119
    if (str == NULL) {
124
        return printf_putnchars("(NULL)", 6, ps);
120
        return printf_putnchars("(NULL)", 6, ps);
125
    }
121
    }
126
 
122
 
127
    count = strlen(str);
123
    count = strlen(str);
128
 
124
 
129
    if (ps->write((void *) str, count, ps->data) == count) {
125
    return ps->write((void *) str, count, ps->data);
130
        return 0;
-
 
131
    }
-
 
132
   
-
 
133
    return EOF;
-
 
134
}
126
}
135
 
127
 
136
/** Print one character to output
128
/** Print one character to output
137
 * @param c one character
129
 * @param c one character
138
 * @param ps output method
130
 * @param ps output method
139
 * @return printed character or EOF
131
 * @return number or printed characters
140
 */
132
 */
141
static int printf_putchar(int c, struct printf_spec *ps)
133
static int printf_putchar(int c, struct printf_spec *ps)
142
{
134
{
143
    unsigned char ch = c;
135
    unsigned char ch = c;
144
   
136
   
145
    if (ps->write((void *) &ch, 1, ps->data) == 1) {
137
    return ps->write((void *) &ch, 1, ps->data);
146
        return c;
-
 
147
    }
-
 
148
   
-
 
149
    return EOF;
-
 
150
}
138
}
151
 
139
 
152
/** Print one formatted character
140
/** Print one formatted character
153
 * @param c character to print
141
 * @param c character to print
154
 * @param width
142
 * @param width
155
 * @param flags
143
 * @param flags
156
 * @return number of printed characters or EOF
144
 * @return number of printed characters, negative value on fail
157
 */
145
 */
158
static int print_char(char c, int width, __u64 flags, struct printf_spec *ps)
146
static int print_char(char c, int width, __u64 flags, struct printf_spec *ps)
159
{
147
{
160
    int counter = 0;
148
    int counter = 0;
161
   
149
   
162
    if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
150
    if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
163
        while (--width > 0) {   /* one space is consumed by character itself hence predecrement */
151
        while (--width > 0) {   /* one space is consumed by character itself hence predecrement */
164
            /* FIXME: painful slow */
152
            /* FIXME: painful slow */
165
            printf_putchar(' ', ps);   
153
            if (printf_putchar(' ', ps) > 0)   
166
            ++counter;
154
                ++counter;
167
        }
155
        }
168
    }
156
    }
169
   
157
   
170
    if (printf_putchar(c, ps) == EOF) {
158
    if (printf_putchar(c, ps) > 0)
171
        return EOF;
159
        counter++;
172
    }
-
 
173
 
160
 
174
    while (--width > 0) { /* one space is consumed by character itself hence predecrement */
161
    while (--width > 0) { /* one space is consumed by character itself hence predecrement */
175
        printf_putchar(' ', ps);
162
        if (printf_putchar(' ', ps) > 0)
176
        ++counter;
163
            ++counter;
177
    }
164
    }
178
   
165
   
179
    return ++counter;
166
    return ++counter;
180
}
167
}
181
 
168
 
182
/** Print one string
169
/** Print one string
183
 * @param s string
170
 * @param s string
184
 * @param width
171
 * @param width
185
 * @param precision
172
 * @param precision
186
 * @param flags
173
 * @param flags
187
 * @return number of printed characters or EOF
174
 * @return number of printed characters or negative value on fail
188
 */
175
 */
189
                       
176
                       
190
static int print_string(char *s, int width, int precision, __u64 flags, struct printf_spec *ps)
177
static int print_string(char *s, int width, int precision, __u64 flags, struct printf_spec *ps)
191
{
178
{
192
    int counter = 0;
179
    int counter = 0;
193
    size_t size;
180
    size_t size;
-
 
181
    int retval;
194
 
182
 
195
    if (s == NULL) {
183
    if (s == NULL) {
196
        return printf_putstr("(NULL)", ps);
184
        return printf_putstr("(NULL)", ps);
197
    }
185
    }
198
   
186
   
199
    size = strlen(s);
187
    size = strlen(s);
200
 
188
 
201
    /* print leading spaces */
189
    /* print leading spaces */
202
 
190
 
203
    if (precision == 0)
191
    if (precision == 0)
204
        precision = size;
192
        precision = size;
205
 
193
 
206
    width -= precision;
194
    width -= precision;
207
   
195
   
208
    if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
196
    if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
209
        while (width-- > 0) {  
197
        while (width-- > 0) {  
210
            printf_putchar(' ', ps);   
198
            if (printf_putchar(' ', ps) == 1)  
211
            counter++;
199
                counter++;
212
        }
200
        }
213
    }
201
    }
214
 
202
 
215
    while (precision > size) {
203
    while (precision > size) {
216
        precision--;
204
        precision--;
217
        printf_putchar(' ', ps);   
205
        if (printf_putchar(' ', ps) == 1)  
218
        ++counter;
206
            ++counter;
219
    }
207
    }
220
   
208
   
221
    if (printf_putnchars(s, precision, ps) == EOF) {
209
    if ((retval = printf_putnchars(s, precision, ps)) < 0) {
222
        return EOF;
210
        return -counter;
223
    }
211
    }
224
 
-
 
225
    counter += precision;
212
    counter += retval; 
226
 
213
 
227
    while (width-- > 0) {
214
    while (width-- > 0) {
228
        printf_putchar(' ', ps);   
215
        if (printf_putchar(' ', ps) == 1)  
229
        ++counter;
216
            ++counter;
230
    }
217
    }
231
   
218
   
232
    return ++counter;
219
    return counter;
233
}
220
}
234
 
221
 
235
 
222
 
236
/** Print number in given base
223
/** Print number in given base
237
 *
224
 *
238
 * Print significant digits of a number in given
225
 * Print significant digits of a number in given
239
 * base.
226
 * base.
240
 *
227
 *
241
 * @param num  Number to print.
228
 * @param num  Number to print.
242
 * @param width
229
 * @param width
243
 * @param precision
230
 * @param precision
244
 * @param base Base to print the number in (should
231
 * @param base Base to print the number in (should
245
 *             be in range 2 .. 16).
232
 *             be in range 2 .. 16).
246
 * @param flags output modifiers
233
 * @param flags output modifiers
247
 * @return number of written characters or EOF
234
 * @return number of written characters or EOF
248
 *
235
 *
249
 */
236
 */
250
static int print_number(__u64 num, int width, int precision, int base , __u64 flags, struct printf_spec *ps)
237
static int print_number(__u64 num, int width, int precision, int base , __u64 flags, struct printf_spec *ps)
251
{
238
{
252
    char *digits = digits_small;
239
    char *digits = digits_small;
253
    char d[PRINT_NUMBER_BUFFER_SIZE];   /* this is good enough even for base == 2, prefix and sign */
240
    char d[PRINT_NUMBER_BUFFER_SIZE];   /* this is good enough even for base == 2, prefix and sign */
254
    char *ptr = &d[PRINT_NUMBER_BUFFER_SIZE - 1];
241
    char *ptr = &d[PRINT_NUMBER_BUFFER_SIZE - 1];
255
    int size = 0; /* size of number with all prefixes and signs */
242
    int size = 0; /* size of number with all prefixes and signs */
256
    int number_size; /* size of plain number */
243
    int number_size; /* size of plain number */
257
    int written = 0;
-
 
258
    char sgn;
244
    char sgn;
-
 
245
    int retval;
-
 
246
    int counter = 0;
259
   
247
   
260
    if (flags & __PRINTF_FLAG_BIGCHARS)
248
    if (flags & __PRINTF_FLAG_BIGCHARS)
261
        digits = digits_big;   
249
        digits = digits_big;   
262
   
250
   
263
    *ptr-- = 0; /* Put zero at end of string */
251
    *ptr-- = 0; /* Put zero at end of string */
264
 
252
 
265
    if (num == 0) {
253
    if (num == 0) {
266
        *ptr-- = '0';
254
        *ptr-- = '0';
267
        size++;
255
        size++;
268
    } else {
256
    } else {
269
        do {
257
        do {
270
            *ptr-- = digits[num % base];
258
            *ptr-- = digits[num % base];
271
            size++;
259
            size++;
272
        } while (num /= base);
260
        } while (num /= base);
273
    }
261
    }
274
   
262
   
275
    number_size = size;
263
    number_size = size;
276
 
264
 
277
    /* Collect sum of all prefixes/signs/... to calculate padding and leading zeroes */
265
    /* Collect sum of all prefixes/signs/... to calculate padding and leading zeroes */
278
    if (flags & __PRINTF_FLAG_PREFIX) {
266
    if (flags & __PRINTF_FLAG_PREFIX) {
279
        switch(base) {
267
        switch(base) {
280
            case 2: /* Binary formating is not standard, but usefull */
268
            case 2: /* Binary formating is not standard, but usefull */
281
                size += 2;
269
                size += 2;
282
                break;
270
                break;
283
            case 8:
271
            case 8:
284
                size++;
272
                size++;
285
                break;
273
                break;
286
            case 16:
274
            case 16:
287
                size += 2;
275
                size += 2;
288
                break;
276
                break;
289
        }
277
        }
290
    }
278
    }
291
 
279
 
292
    sgn = 0;
280
    sgn = 0;
293
    if (flags & __PRINTF_FLAG_SIGNED) {
281
    if (flags & __PRINTF_FLAG_SIGNED) {
294
        if (flags & __PRINTF_FLAG_NEGATIVE) {
282
        if (flags & __PRINTF_FLAG_NEGATIVE) {
295
            sgn = '-';
283
            sgn = '-';
296
            size++;
284
            size++;
297
        } else if (flags & __PRINTF_FLAG_SHOWPLUS) {
285
        } else if (flags & __PRINTF_FLAG_SHOWPLUS) {
298
                sgn = '+';
286
                sgn = '+';
299
                size++;
287
                size++;
300
            } else if (flags & __PRINTF_FLAG_SPACESIGN) {
288
            } else if (flags & __PRINTF_FLAG_SPACESIGN) {
301
                    sgn = ' ';
289
                    sgn = ' ';
302
                    size++;
290
                    size++;
303
                }
291
                }
304
    }
292
    }
305
 
293
 
306
    if (flags & __PRINTF_FLAG_LEFTALIGNED) {
294
    if (flags & __PRINTF_FLAG_LEFTALIGNED) {
307
        flags &= ~__PRINTF_FLAG_ZEROPADDED;
295
        flags &= ~__PRINTF_FLAG_ZEROPADDED;
308
    }
296
    }
309
 
297
 
310
    /* if number is leftaligned or precision is specified then zeropadding is ignored */
298
    /* if number is leftaligned or precision is specified then zeropadding is ignored */
311
    if (flags & __PRINTF_FLAG_ZEROPADDED) {
299
    if (flags & __PRINTF_FLAG_ZEROPADDED) {
312
        if ((precision == 0) && (width > size)) {
300
        if ((precision == 0) && (width > size)) {
313
            precision = width - size + number_size;
301
            precision = width - size + number_size;
314
        }
302
        }
315
    }
303
    }
316
 
304
 
317
    /* print leading spaces */
305
    /* print leading spaces */
318
    if (number_size > precision) /* We must print whole number not only a part */
306
    if (number_size > precision) /* We must print whole number not only a part */
319
        precision = number_size;
307
        precision = number_size;
320
 
308
 
321
    width -= precision + size - number_size;
309
    width -= precision + size - number_size;
322
   
310
   
323
    if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
311
    if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
324
        while (width-- > 0) {  
312
        while (width-- > 0) {  
325
            printf_putchar(' ', ps);   
313
            if (printf_putchar(' ', ps) == 1)  
326
            written++;
314
                counter++;
327
        }
315
        }
328
    }
316
    }
329
   
317
   
-
 
318
   
330
    /* print sign */
319
    /* print sign */
331
    if (sgn) {
320
    if (sgn) {
332
        printf_putchar(sgn, ps);
321
        if (printf_putchar(sgn, ps) == 1)
333
        written++;
322
            counter++;
334
    }
323
    }
335
   
324
   
336
    /* print prefix */
325
    /* print prefix */
337
   
326
   
338
    if (flags & __PRINTF_FLAG_PREFIX) {
327
    if (flags & __PRINTF_FLAG_PREFIX) {
339
        switch(base) {
328
        switch(base) {
340
            case 2: /* Binary formating is not standard, but usefull */
329
            case 2: /* Binary formating is not standard, but usefull */
341
                printf_putchar('0', ps);
330
                if (printf_putchar('0', ps) == 1)
-
 
331
                    counter++;
342
                if (flags & __PRINTF_FLAG_BIGCHARS) {
332
                if (flags & __PRINTF_FLAG_BIGCHARS) {
343
                    printf_putchar('B', ps);
333
                    if (printf_putchar('B', ps) == 1)
-
 
334
                        counter++;
344
                } else {
335
                } else {
345
                    printf_putchar('b', ps);
336
                    if (printf_putchar('b', ps) == 1)
-
 
337
                        counter++;
346
                }
338
                }
347
                written += 2;
-
 
348
                break;
339
                break;
349
            case 8:
340
            case 8:
350
                printf_putchar('o', ps);
341
                if (printf_putchar('o', ps) == 1)
351
                written++;
342
                    counter++;
352
                break;
343
                break;
353
            case 16:
344
            case 16:
354
                printf_putchar('0', ps);
345
                if (printf_putchar('0', ps) == 1)
-
 
346
                    counter++;
355
                if (flags & __PRINTF_FLAG_BIGCHARS) {
347
                if (flags & __PRINTF_FLAG_BIGCHARS) {
356
                    printf_putchar('X', ps);
348
                    if (printf_putchar('X', ps) == 1)
-
 
349
                        counter++;
357
                } else {
350
                } else {
358
                    printf_putchar('x', ps);
351
                    if (printf_putchar('x', ps) == 1)
-
 
352
                        counter++;
359
                }
353
                }
360
                written += 2;
-
 
361
                break;
354
                break;
362
        }
355
        }
363
    }
356
    }
364
 
357
 
365
    /* print leading zeroes */
358
    /* print leading zeroes */
366
    precision -= number_size;
359
    precision -= number_size;
367
    while (precision-- > 0) {  
360
    while (precision-- > 0) {  
368
        printf_putchar('0', ps);   
361
        if (printf_putchar('0', ps) == 1)
369
        written++;
362
            counter++;
370
    }
363
    }
371
 
364
 
372
   
365
   
373
    /* print number itself */
366
    /* print number itself */
374
 
367
 
375
    written += printf_putstr(++ptr, ps);
368
    if ((retval = printf_putstr(++ptr, ps)) > 0) {
-
 
369
        counter += retval;
-
 
370
    }
376
   
371
   
377
    /* print ending spaces */
372
    /* print ending spaces */
378
   
373
   
379
    while (width-- > 0) {  
374
    while (width-- > 0) {  
380
        printf_putchar(' ', ps);   
375
        if (printf_putchar(' ', ps) == 1)  
381
        written++;
376
            counter++;
382
    }
377
    }
383
 
378
 
384
    return written;
379
    return counter;
385
}
380
}
386
 
381
 
387
 
382
 
388
/** Print formatted string.
383
/** Print formatted string.
389
 *
384
 *
390
 * Print string formatted according to the fmt parameter
385
 * Print string formatted according to the fmt parameter
391
 * and variadic arguments. Each formatting directive
386
 * and variadic arguments. Each formatting directive
392
 * must have the following form:
387
 * must have the following form:
393
 *
388
 *
394
 *  \% [ FLAGS ] [ WIDTH ] [ .PRECISION ] [ TYPE ] CONVERSION
389
 *  \% [ FLAGS ] [ WIDTH ] [ .PRECISION ] [ TYPE ] CONVERSION
395
 *
390
 *
396
 * FLAGS:@n
391
 * FLAGS:@n
397
 *  - "#" Force to print prefix.
392
 *  - "#" Force to print prefix.
398
 *  For conversion \%o the prefix is 0, for %x and \%X prefixes are 0x and 0X
393
 *  For conversion \%o the prefix is 0, for %x and \%X prefixes are 0x and 0X
399
 *  and for conversion \%b the prefix is 0b.
394
 *  and for conversion \%b the prefix is 0b.
400
 *
395
 *
401
 *  - "-"   Align to left.
396
 *  - "-"   Align to left.
402
 *
397
 *
403
 *  - "+"   Print positive sign just as negative.
398
 *  - "+"   Print positive sign just as negative.
404
 *
399
 *
405
 *  - " "   If the printed number is positive and "+" flag is not set, print space in
400
 *  - " "   If the printed number is positive and "+" flag is not set, print space in
406
 *  place of sign.
401
 *  place of sign.
407
 *
402
 *
408
 *  - "0"   Print 0 as padding instead of spaces. Zeroes are placed between sign and the
403
 *  - "0"   Print 0 as padding instead of spaces. Zeroes are placed between sign and the
409
 *  rest of the number. This flag is ignored if "-" flag is specified.
404
 *  rest of the number. This flag is ignored if "-" flag is specified.
410
 *
405
 *
411
 * WIDTH:@n
406
 * WIDTH:@n
412
 *  - Specify minimal width of printed argument. If it is bigger, width is ignored.
407
 *  - Specify minimal width of printed argument. If it is bigger, width is ignored.
413
 * If width is specified with a "*" character instead of number, width is taken from
408
 * If width is specified with a "*" character instead of number, width is taken from
414
 * parameter list. And integer parameter is expected before parameter for processed
409
 * parameter list. And integer parameter is expected before parameter for processed
415
 * conversion specification. If this value is negative its absolute value is taken
410
 * conversion specification. If this value is negative its absolute value is taken
416
 * and the "-" flag is set.
411
 * and the "-" flag is set.
417
 *
412
 *
418
 * PRECISION:@n
413
 * PRECISION:@n
419
 *  - Value precision. For numbers it specifies minimum valid numbers.
414
 *  - Value precision. For numbers it specifies minimum valid numbers.
420
 * Smaller numbers are printed with leading zeroes. Bigger numbers are not affected.
415
 * Smaller numbers are printed with leading zeroes. Bigger numbers are not affected.
421
 * Strings with more than precision characters are cut off.
416
 * Strings with more than precision characters are cut off.
422
 * Just as with width, an "*" can be used used instead of a number.
417
 * Just as with width, an "*" can be used used instead of a number.
423
 * An integer value is then expected in parameters. When both width and precision
418
 * An integer value is then expected in parameters. When both width and precision
424
 * are specified using "*", the first parameter is used for width and the second one
419
 * are specified using "*", the first parameter is used for width and the second one
425
 * for precision.
420
 * for precision.
426
 *
421
 *
427
 * TYPE:@n
422
 * TYPE:@n
428
 *  - "hh"  Signed or unsigned char.@n
423
 *  - "hh"  Signed or unsigned char.@n
429
 *  - "h"   Signed or usigned short.@n
424
 *  - "h"   Signed or usigned short.@n
430
 *  - ""    Signed or usigned int (default value).@n
425
 *  - ""    Signed or usigned int (default value).@n
431
 *  - "l"   Signed or usigned long int.@n
426
 *  - "l"   Signed or usigned long int.@n
432
 *  - "ll"  Signed or usigned long long int.@n
427
 *  - "ll"  Signed or usigned long long int.@n
433
 *  - "z"   __native (non-standard extension).@n
428
 *  - "z"   __native (non-standard extension).@n
434
 *
429
 *
435
 *
430
 *
436
 * CONVERSION:@n
431
 * CONVERSION:@n
437
 *  - % Print percentile character itself.
432
 *  - % Print percentile character itself.
438
 *
433
 *
439
 *  - c Print single character.
434
 *  - c Print single character.
440
 *
435
 *
441
 *  - s Print zero terminated string. If a NULL value is passed as value, "(NULL)" is printed instead.
436
 *  - s Print zero terminated string. If a NULL value is passed as value, "(NULL)" is printed instead.
442
 *
437
 *
443
 *  - P, p  Print value of a pointer. Void * value is expected and it is printed in hexadecimal notation with prefix
438
 *  - P, p  Print value of a pointer. Void * value is expected and it is printed in hexadecimal notation with prefix
444
 *  (as with \%#X or \%#x for 32bit or \%#X / \%#x for 64bit long pointers).
439
 *  (as with \%#X or \%#x for 32bit or \%#X / \%#x for 64bit long pointers).
445
 *
440
 *
446
 *  - b Print value as unsigned binary number. Prefix is not printed by default. (Nonstandard extension.)
441
 *  - b Print value as unsigned binary number. Prefix is not printed by default. (Nonstandard extension.)
447
 *
442
 *
448
 *  - o Print value as unsigned octal number. Prefix is not printed by default.
443
 *  - o Print value as unsigned octal number. Prefix is not printed by default.
449
 *
444
 *
450
 *  - d,i   Print signed decimal number. There is no difference between d and i conversion.
445
 *  - d,i   Print signed decimal number. There is no difference between d and i conversion.
451
 *
446
 *
452
 *  - u Print unsigned decimal number.
447
 *  - u Print unsigned decimal number.
453
 *
448
 *
454
 *  - X, x  Print hexadecimal number with upper- or lower-case. Prefix is not printed by default.
449
 *  - X, x  Print hexadecimal number with upper- or lower-case. Prefix is not printed by default.
455
 *
450
 *
456
 * All other characters from fmt except the formatting directives
451
 * All other characters from fmt except the formatting directives
457
 * are printed in verbatim.
452
 * are printed in verbatim.
458
 *
453
 *
459
 * @param fmt Formatting NULL terminated string.
454
 * @param fmt Formatting NULL terminated string.
460
 * @return Number of printed characters or negative value on failure.
455
 * @return Number of printed characters or negative value on failure.
461
 */
456
 */
462
int printf_core(const char *fmt, struct printf_spec *ps, va_list ap)
457
int printf_core(const char *fmt, struct printf_spec *ps, va_list ap)
463
{
458
{
464
    int irqpri;
459
    int irqpri;
465
    int i = 0, j = 0; /**< i is index of currently processed char from fmt, j is index to the first not printed nonformating character */
460
    int i = 0, j = 0; /**< i is index of currently processed char from fmt, j is index to the first not printed nonformating character */
466
    int end;
461
    int end;
467
    int counter; /**< counter of printed characters */
462
    int counter; /**< counter of printed characters */
468
    int retval; /**< used to store return values from called functions */
463
    int retval; /**< used to store return values from called functions */
469
    char c;
464
    char c;
470
    qualifier_t qualifier;  /* type of argument */
465
    qualifier_t qualifier;  /* type of argument */
471
    int base;   /**< base in which will be parameter (numbers only) printed */
466
    int base;   /**< base in which will be parameter (numbers only) printed */
472
    __u64 number; /**< argument value */
467
    __u64 number; /**< argument value */
473
    size_t  size; /**< byte size of integer parameter */
468
    size_t  size; /**< byte size of integer parameter */
474
    int width, precision;
469
    int width, precision;
475
    __u64 flags;
470
    __u64 flags;
476
   
471
   
477
    counter = 0;
472
    counter = 0;
478
   
473
   
479
    irqpri = interrupts_disable();
474
    irqpri = interrupts_disable();
480
    spinlock_lock(&printflock);
475
    spinlock_lock(&printflock);
481
 
476
 
482
    while ((c = fmt[i])) {
477
    while ((c = fmt[i])) {
483
        /* control character */
478
        /* control character */
484
        if (c == '%' ) {
479
        if (c == '%' ) {
485
            /* print common characters if any processed */ 
480
            /* print common characters if any processed */ 
486
            if (i > j) {
481
            if (i > j) {
487
                if ((retval = printf_putnchars(&fmt[j], (size_t)(i - j), ps)) == EOF) { /* error */
482
                if ((retval = printf_putnchars(&fmt[j], (size_t)(i - j), ps)) < 0) { /* error */
488
                    counter = -counter;
483
                    counter = -counter;
489
                    goto out;
484
                    goto out;
490
                }
485
                }
491
                counter += retval;
486
                counter += retval;
492
            }
487
            }
493
       
488
       
494
            j = i;
489
            j = i;
495
            /* parse modifiers */
490
            /* parse modifiers */
496
            flags = 0;
491
            flags = 0;
497
            end = 0;
492
            end = 0;
498
           
493
           
499
            do {
494
            do {
500
                ++i;
495
                ++i;
501
                switch (c = fmt[i]) {
496
                switch (c = fmt[i]) {
502
                    case '#': flags |= __PRINTF_FLAG_PREFIX; break;
497
                    case '#': flags |= __PRINTF_FLAG_PREFIX; break;
503
                    case '-': flags |= __PRINTF_FLAG_LEFTALIGNED; break;
498
                    case '-': flags |= __PRINTF_FLAG_LEFTALIGNED; break;
504
                    case '+': flags |= __PRINTF_FLAG_SHOWPLUS; break;
499
                    case '+': flags |= __PRINTF_FLAG_SHOWPLUS; break;
505
                    case ' ': flags |= __PRINTF_FLAG_SPACESIGN; break;
500
                    case ' ': flags |= __PRINTF_FLAG_SPACESIGN; break;
506
                    case '0': flags |= __PRINTF_FLAG_ZEROPADDED; break;
501
                    case '0': flags |= __PRINTF_FLAG_ZEROPADDED; break;
507
                    default: end = 1;
502
                    default: end = 1;
508
                }; 
503
                }; 
509
               
504
               
510
            } while (end == 0);
505
            } while (end == 0);
511
           
506
           
512
            /* width & '*' operator */
507
            /* width & '*' operator */
513
            width = 0;
508
            width = 0;
514
            if (isdigit(fmt[i])) {
509
            if (isdigit(fmt[i])) {
515
                while (isdigit(fmt[i])) {
510
                while (isdigit(fmt[i])) {
516
                    width *= 10;
511
                    width *= 10;
517
                    width += fmt[i++] - '0';
512
                    width += fmt[i++] - '0';
518
                }
513
                }
519
            } else if (fmt[i] == '*') {
514
            } else if (fmt[i] == '*') {
520
                /* get width value from argument list*/
515
                /* get width value from argument list*/
521
                i++;
516
                i++;
522
                width = (int)va_arg(ap, int);
517
                width = (int)va_arg(ap, int);
523
                if (width < 0) {
518
                if (width < 0) {
524
                    /* negative width means to set '-' flag */
519
                    /* negative width means to set '-' flag */
525
                    width *= -1;
520
                    width *= -1;
526
                    flags |= __PRINTF_FLAG_LEFTALIGNED;
521
                    flags |= __PRINTF_FLAG_LEFTALIGNED;
527
                }
522
                }
528
            }
523
            }
529
           
524
           
530
            /* precision and '*' operator */   
525
            /* precision and '*' operator */   
531
            precision = 0;
526
            precision = 0;
532
            if (fmt[i] == '.') {
527
            if (fmt[i] == '.') {
533
                ++i;
528
                ++i;
534
                if (isdigit(fmt[i])) {
529
                if (isdigit(fmt[i])) {
535
                    while (isdigit(fmt[i])) {
530
                    while (isdigit(fmt[i])) {
536
                        precision *= 10;
531
                        precision *= 10;
537
                        precision += fmt[i++] - '0';
532
                        precision += fmt[i++] - '0';
538
                    }
533
                    }
539
                } else if (fmt[i] == '*') {
534
                } else if (fmt[i] == '*') {
540
                    /* get precision value from argument list*/
535
                    /* get precision value from argument list*/
541
                    i++;
536
                    i++;
542
                    precision = (int)va_arg(ap, int);
537
                    precision = (int)va_arg(ap, int);
543
                    if (precision < 0) {
538
                    if (precision < 0) {
544
                        /* negative precision means to ignore it */
539
                        /* negative precision means to ignore it */
545
                        precision = 0;
540
                        precision = 0;
546
                    }
541
                    }
547
                }
542
                }
548
            }
543
            }
549
 
544
 
550
            switch (fmt[i++]) {
545
            switch (fmt[i++]) {
551
                /** TODO: unimplemented qualifiers:
546
                /** TODO: unimplemented qualifiers:
552
                 * t ptrdiff_t - ISO C 99
547
                 * t ptrdiff_t - ISO C 99
553
                 */
548
                 */
554
                case 'h':   /* char or short */
549
                case 'h':   /* char or short */
555
                    qualifier = PrintfQualifierShort;
550
                    qualifier = PrintfQualifierShort;
556
                    if (fmt[i] == 'h') {
551
                    if (fmt[i] == 'h') {
557
                        i++;
552
                        i++;
558
                        qualifier = PrintfQualifierByte;
553
                        qualifier = PrintfQualifierByte;
559
                    }
554
                    }
560
                    break;
555
                    break;
561
                case 'l':   /* long or long long*/
556
                case 'l':   /* long or long long*/
562
                    qualifier = PrintfQualifierLong;
557
                    qualifier = PrintfQualifierLong;
563
                    if (fmt[i] == 'l') {
558
                    if (fmt[i] == 'l') {
564
                        i++;
559
                        i++;
565
                        qualifier = PrintfQualifierLongLong;
560
                        qualifier = PrintfQualifierLongLong;
566
                    }
561
                    }
567
                    break;
562
                    break;
568
                case 'z':   /* __native */
563
                case 'z':   /* __native */
569
                    qualifier = PrintfQualifierNative;
564
                    qualifier = PrintfQualifierNative;
570
                    break;
565
                    break;
571
                default:
566
                default:
572
                    qualifier = PrintfQualifierInt; /* default type */
567
                    qualifier = PrintfQualifierInt; /* default type */
573
                    --i;
568
                    --i;
574
            }  
569
            }  
575
           
570
           
576
            base = 10;
571
            base = 10;
577
 
572
 
578
            switch (c = fmt[i]) {
573
            switch (c = fmt[i]) {
579
 
574
 
580
                /*
575
                /*
581
                * String and character conversions.
576
                * String and character conversions.
582
                */
577
                */
583
                case 's':
578
                case 's':
584
                    if ((retval = print_string(va_arg(ap, char*), width, precision, flags, ps)) == EOF) {
579
                    if ((retval = print_string(va_arg(ap, char*), width, precision, flags, ps)) < 0) {
585
                        counter = -counter;
580
                        counter = -counter;
586
                        goto out;
581
                        goto out;
587
                    };
582
                    };
588
                   
583
                   
589
                    counter += retval;
584
                    counter += retval;
590
                    j = i + 1;
585
                    j = i + 1;
591
                    goto next_char;
586
                    goto next_char;
592
                case 'c':
587
                case 'c':
593
                    c = va_arg(ap, unsigned int);
588
                    c = va_arg(ap, unsigned int);
594
                    if ((retval = print_char(c, width, flags, ps)) == EOF) {
589
                    if ((retval = print_char(c, width, flags, ps)) < 0) {
595
                        counter = -counter;
590
                        counter = -counter;
596
                        goto out;
591
                        goto out;
597
                    };
592
                    };
598
                   
593
                   
599
                    counter += retval;
594
                    counter += retval;
600
                    j = i + 1;
595
                    j = i + 1;
601
                    goto next_char;
596
                    goto next_char;
602
 
597
 
603
                /*
598
                /*
604
                 * Integer values
599
                 * Integer values
605
                */
600
                */
606
                case 'P': /* pointer */
601
                case 'P': /* pointer */
607
                        flags |= __PRINTF_FLAG_BIGCHARS;
602
                        flags |= __PRINTF_FLAG_BIGCHARS;
608
                case 'p':
603
                case 'p':
609
                    flags |= __PRINTF_FLAG_PREFIX;
604
                    flags |= __PRINTF_FLAG_PREFIX;
610
                    base = 16;
605
                    base = 16;
611
                    qualifier = PrintfQualifierPointer;
606
                    qualifier = PrintfQualifierPointer;
612
                    break; 
607
                    break; 
613
                case 'b':
608
                case 'b':
614
                    base = 2;
609
                    base = 2;
615
                    break;
610
                    break;
616
                case 'o':
611
                case 'o':
617
                    base = 8;
612
                    base = 8;
618
                    break;
613
                    break;
619
                case 'd':
614
                case 'd':
620
                case 'i':
615
                case 'i':
621
                    flags |= __PRINTF_FLAG_SIGNED;  
616
                    flags |= __PRINTF_FLAG_SIGNED;  
622
                case 'u':
617
                case 'u':
623
                    break;
618
                    break;
624
                case 'X':
619
                case 'X':
625
                    flags |= __PRINTF_FLAG_BIGCHARS;
620
                    flags |= __PRINTF_FLAG_BIGCHARS;
626
                case 'x':
621
                case 'x':
627
                    base = 16;
622
                    base = 16;
628
                    break;
623
                    break;
629
                /* percentile itself */
624
                /* percentile itself */
630
                case '%':
625
                case '%':
631
                    j = i;
626
                    j = i;
632
                    goto next_char;
627
                    goto next_char;
633
                /*
628
                /*
634
                * Bad formatting.
629
                * Bad formatting.
635
                */
630
                */
636
                default:
631
                default:
637
                    /* Unknown format
632
                    /* Unknown format
638
                     *  now, the j is index of '%' so we will
633
                     *  now, the j is index of '%' so we will
639
                     * print whole bad format sequence
634
                     * print whole bad format sequence
640
                     */
635
                     */
641
                    goto next_char;    
636
                    goto next_char;    
642
            }
637
            }
643
       
638
       
644
       
639
       
645
        /* Print integers */
640
        /* Print integers */
646
            /* print number */
641
            /* print number */
647
            switch (qualifier) {
642
            switch (qualifier) {
648
                case PrintfQualifierByte:
643
                case PrintfQualifierByte:
649
                    size = sizeof(unsigned char);
644
                    size = sizeof(unsigned char);
650
                    number = (__u64)va_arg(ap, unsigned int);
645
                    number = (__u64)va_arg(ap, unsigned int);
651
                    break;
646
                    break;
652
                case PrintfQualifierShort:
647
                case PrintfQualifierShort:
653
                    size = sizeof(unsigned short);
648
                    size = sizeof(unsigned short);
654
                    number = (__u64)va_arg(ap, unsigned int);
649
                    number = (__u64)va_arg(ap, unsigned int);
655
                    break;
650
                    break;
656
                case PrintfQualifierInt:
651
                case PrintfQualifierInt:
657
                    size = sizeof(unsigned int);
652
                    size = sizeof(unsigned int);
658
                    number = (__u64)va_arg(ap, unsigned int);
653
                    number = (__u64)va_arg(ap, unsigned int);
659
                    break;
654
                    break;
660
                case PrintfQualifierLong:
655
                case PrintfQualifierLong:
661
                    size = sizeof(unsigned long);
656
                    size = sizeof(unsigned long);
662
                    number = (__u64)va_arg(ap, unsigned long);
657
                    number = (__u64)va_arg(ap, unsigned long);
663
                    break;
658
                    break;
664
                case PrintfQualifierLongLong:
659
                case PrintfQualifierLongLong:
665
                    size = sizeof(unsigned long long);
660
                    size = sizeof(unsigned long long);
666
                    number = (__u64)va_arg(ap, unsigned long long);
661
                    number = (__u64)va_arg(ap, unsigned long long);
667
                    break;
662
                    break;
668
                case PrintfQualifierPointer:
663
                case PrintfQualifierPointer:
669
                    size = sizeof(void *);
664
                    size = sizeof(void *);
670
                    number = (__u64)(unsigned long)va_arg(ap, void *);
665
                    number = (__u64)(unsigned long)va_arg(ap, void *);
671
                    break;
666
                    break;
672
                case PrintfQualifierNative:
667
                case PrintfQualifierNative:
673
                    size = sizeof(__native);
668
                    size = sizeof(__native);
674
                    number = (__u64)va_arg(ap, __native);
669
                    number = (__u64)va_arg(ap, __native);
675
                    break;
670
                    break;
676
                default: /* Unknown qualifier */
671
                default: /* Unknown qualifier */
677
                    counter = -counter;
672
                    counter = -counter;
678
                    goto out;
673
                    goto out;
679
            }
674
            }
680
           
675
           
681
            if (flags & __PRINTF_FLAG_SIGNED) {
676
            if (flags & __PRINTF_FLAG_SIGNED) {
682
                if (number & (0x1 << (size*8 - 1))) {
677
                if (number & (0x1 << (size*8 - 1))) {
683
                    flags |= __PRINTF_FLAG_NEGATIVE;
678
                    flags |= __PRINTF_FLAG_NEGATIVE;
684
               
679
               
685
                    if (size == sizeof(__u64)) {
680
                    if (size == sizeof(__u64)) {
686
                        number = -((__s64)number);
681
                        number = -((__s64)number);
687
                    } else {
682
                    } else {
688
                        number = ~number;
683
                        number = ~number;
689
                        number &= (~((0xFFFFFFFFFFFFFFFFll) <<  (size * 8)));
684
                        number &= (~((0xFFFFFFFFFFFFFFFFll) <<  (size * 8)));
690
                        number++;
685
                        number++;
691
                    }
686
                    }
692
                }
687
                }
693
            }
688
            }
694
 
689
 
695
            if ((retval = print_number(number, width, precision, base, flags, ps)) == EOF ) {
690
            if ((retval = print_number(number, width, precision, base, flags, ps)) < 0) {
696
                counter = -counter;
691
                counter = -counter;
697
                goto out;
692
                goto out;
698
            };
693
            };
699
 
694
 
700
            counter += retval;
695
            counter += retval;
701
            j = i + 1;
696
            j = i + 1;
702
        }  
697
        }  
703
next_char:
698
next_char:
704
           
699
           
705
        ++i;
700
        ++i;
706
    }
701
    }
707
   
702
   
708
    if (i > j) {
703
    if (i > j) {
709
        if ((retval = printf_putnchars(&fmt[j], (__native)(i - j), ps)) == EOF) { /* error */
704
        if ((retval = printf_putnchars(&fmt[j], (__native)(i - j), ps)) < 0) { /* error */
710
            counter = -counter;
705
            counter = -counter;
711
            goto out;
706
            goto out;
712
           
707
           
713
        }
708
        }
714
        counter += retval;
709
        counter += retval;
715
    }
710
    }
716
 
711
 
717
out:
712
out:
718
    spinlock_unlock(&printflock);
713
    spinlock_unlock(&printflock);
719
    interrupts_restore(irqpri);
714
    interrupts_restore(irqpri);
720
   
715
   
721
    return counter;
716
    return counter;
722
}
717
}
723
 
718
 
724
 
719