Subversion Repositories HelenOS

Rev

Rev 2131 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2131 Rev 2307
Line 36... Line 36...
36
 */
36
 */
37
 
37
 
38
#include <printf/printf_core.h>
38
#include <printf/printf_core.h>
39
#include <putchar.h>
39
#include <putchar.h>
40
#include <print.h>
40
#include <print.h>
41
#include <synch/spinlock.h>
-
 
42
#include <arch/arg.h>
41
#include <arch/arg.h>
43
#include <arch/asm.h>
-
 
44
 
-
 
45
#include <arch.h>
42
#include <arch.h>
46
 
43
 
47
SPINLOCK_INITIALIZE(printflock);            /**< printf spinlock */
-
 
48
 
-
 
49
#define __PRINTF_FLAG_PREFIX        0x00000001  /**< show prefixes 0x or 0*/
44
#define __PRINTF_FLAG_PREFIX        0x00000001  /**< show prefixes 0x or 0*/
50
#define __PRINTF_FLAG_SIGNED        0x00000002  /**< signed / unsigned number */
45
#define __PRINTF_FLAG_SIGNED        0x00000002  /**< signed / unsigned number */
51
#define __PRINTF_FLAG_ZEROPADDED    0x00000004  /**< print leading zeroes */
46
#define __PRINTF_FLAG_ZEROPADDED    0x00000004  /**< print leading zeroes */
52
#define __PRINTF_FLAG_LEFTALIGNED   0x00000010  /**< align to left */
47
#define __PRINTF_FLAG_LEFTALIGNED   0x00000010  /**< align to left */
53
#define __PRINTF_FLAG_SHOWPLUS      0x00000020  /**< always show + sign */
48
#define __PRINTF_FLAG_SHOWPLUS      0x00000020  /**< always show + sign */
Line 456... Line 451...
456
 * @param fmt Formatting NULL terminated string.
451
 * @param fmt Formatting NULL terminated string.
457
 * @return Number of printed characters or negative value on failure.
452
 * @return Number of printed characters or negative value on failure.
458
 */
453
 */
459
int printf_core(const char *fmt, struct printf_spec *ps, va_list ap)
454
int printf_core(const char *fmt, struct printf_spec *ps, va_list ap)
460
{
455
{
461
    int irqpri;
-
 
462
    int i = 0, j = 0; /**< i is index of currently processed char from fmt, j is index to the first not printed nonformating character */
456
    int i = 0, j = 0; /**< i is index of currently processed char from fmt, j is index to the first not printed nonformating character */
463
    int end;
457
    int end;
464
    int counter; /**< counter of printed characters */
458
    int counter; /**< counter of printed characters */
465
    int retval; /**< used to store return values from called functions */
459
    int retval; /**< used to store return values from called functions */
466
    char c;
460
    char c;
Line 470... Line 464...
470
    size_t  size; /**< byte size of integer parameter */
464
    size_t  size; /**< byte size of integer parameter */
471
    int width, precision;
465
    int width, precision;
472
    uint64_t flags;
466
    uint64_t flags;
473
   
467
   
474
    counter = 0;
468
    counter = 0;
475
   
469
       
476
    irqpri = interrupts_disable();
-
 
477
    spinlock_lock(&printflock);
-
 
478
 
-
 
479
    while ((c = fmt[i])) {
470
    while ((c = fmt[i])) {
480
        /* control character */
471
        /* control character */
481
        if (c == '%' ) {
472
        if (c == '%' ) {
482
            /* print common characters if any processed */ 
473
            /* print common characters if any processed */ 
483
            if (i > j) {
474
            if (i > j) {
Line 710... Line 701...
710
        }
701
        }
711
        counter += retval;
702
        counter += retval;
712
    }
703
    }
713
 
704
 
714
out:
705
out:
715
    spinlock_unlock(&printflock);
-
 
716
    interrupts_restore(irqpri);
-
 
717
   
706
   
718
    return counter;
707
    return counter;
719
}
708
}
720
 
709
 
721
/** @}
710
/** @}