Subversion Repositories HelenOS-historic

Rev

Rev 42 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 42 Rev 61
Line 30... Line 30...
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
 
33
 
34
 
34
 
35
static char digits[] = "0123456789abcdef";
35
static char digits[] = "0123456789abcdef"; /**< Hexadecimal characters */
36
static spinlock_t printflock;
36
static spinlock_t printflock;              /**< printf spinlock */
37
 
37
 
-
 
38
 
-
 
39
/** Print NULL terminated string
-
 
40
 *
-
 
41
 * Print characters from str using putchar() until
-
 
42
 * \x00 character is reached.
-
 
43
 *
-
 
44
 * @param str Characters to print.
-
 
45
 *
-
 
46
 */
38
void print_str(char *str)
47
void print_str(char *str)
39
{
48
{
40
        int i = 0;
49
        int i = 0;
41
    char c;
50
    char c;
42
   
51
   
43
    while (c = str[i++])
52
    while (c = str[i++])
44
        putchar(c);
53
        putchar(c);
45
}
54
}
46
 
55
 
47
 
56
 
-
 
57
/** Print hexadecimal digits
48
/*
58
 *
49
 * This is a universal function for printing hexadecimal numbers of fixed
59
 * Print fixed count of hexadecimal digits from
-
 
60
 * the number num. The digits are printed in
-
 
61
 * natural left-to-right order starting with
50
 * width.
62
 * the width-th digit.
-
 
63
 *
-
 
64
 * @param num   Number containing digits.
-
 
65
 * @param width Count of digits to print.
-
 
66
 *
51
 */
67
 */
52
void print_fixed_hex(__native num, int width)
68
void print_fixed_hex(__native num, int width)
53
{
69
{
54
    int i;
70
    int i;
55
   
71
   
56
    for (i = width*8 - 4; i >= 0; i -= 4)
72
    for (i = width*8 - 4; i >= 0; i -= 4)
57
        putchar(digits[(num>>i) & 0xf]);
73
        putchar(digits[(num>>i) & 0xf]);
58
}
74
}
59
 
75
 
-
 
76
 
-
 
77
/** Print number in given base
60
/*
78
 *
61
 * This is a universal function for printing decimal and hexadecimal numbers.
79
 * Print significant digits of a number in given
-
 
80
 * base.
-
 
81
 *
-
 
82
 * @param num  Number to print.
-
 
83
 * @param base Base to print the number in (should
62
 * It prints only significant digits.
84
 *             be in range 2 .. 16).
-
 
85
 *
63
 */
86
 */
64
void print_number(__native num, int base)
87
void print_number(__native num, int base)
65
{
88
{
66
    char d[sizeof(__native)*8+1];       /* this is good enough even for base == 2 */
89
    char d[sizeof(__native)*8+1];       /* this is good enough even for base == 2 */
67
        int i = sizeof(__native)*8-1;
90
        int i = sizeof(__native)*8-1;
Line 72... Line 95...
72
   
95
   
73
    d[sizeof(__native)*8] = 0; 
96
    d[sizeof(__native)*8] = 0; 
74
    print_str(&d[i + 1]);
97
    print_str(&d[i + 1]);
75
}
98
}
76
 
99
 
-
 
100
 
-
 
101
/** General formatted text print
77
/*
102
 *
-
 
103
 * Print text formatted according the fmt parameter
-
 
104
 * and variant arguments. Each formatting directive
-
 
105
 * begins with % (percentage) character and one of the
-
 
106
 * following character:
-
 
107
 *
-
 
108
 * %    Prints the percentage character.
78
 * This is our function for printing formatted text.
109
 * s    The next variant argument is threated as char*
79
 * It's much simpler than the user-space one.
110
 *      and printed as a NULL terminated string.
-
 
111
 * c    The next variant argument is threated as a single char.
-
 
112
 * l    The next variant argument is threated as a 32b integer
-
 
113
 *      and printed in full hexadecimal width.
-
 
114
 * L    As with 'l', but '0x' is prefixed.
-
 
115
 * w    The next variant argument is threated as a 16b integer
-
 
116
 *      and printed in full hexadecimal width.
-
 
117
 * W    As with 'w', but '0x' is prefixed.
-
 
118
 * b    The next variant argument is threated as a 8b integer
-
 
119
 *      and printed in full hexadecimal width.
-
 
120
 * N    As with 'b', but '0x' is prefixed.
-
 
121
 * d    The next variant argument is threated as integer
-
 
122
 *      and printed in standard decimal format (only significant
-
 
123
 *      digits).
-
 
124
 * x    The next variant argument is threated as integer
-
 
125
 *      and printed in standard hexadecimal format (only significant
-
 
126
 *      digits).
-
 
127
 * X    As with 'x', but '0x' is prefixed.
-
 
128
 *
-
 
129
 * All other characters from fmt except the formatting directives
80
 * We are greateful for this function.
130
 * are printed in verbatim.
-
 
131
 *
-
 
132
 * @param fmt Formatting NULL terminated string.
-
 
133
 *
81
 */
134
 */
82
void printf(char *fmt, ...)
135
void printf(char *fmt, ...)
83
{
136
{
84
    int irqpri, i = 0;
137
    int irqpri, i = 0;
85
    va_list ap;
138
    va_list ap;