Subversion Repositories HelenOS-historic

Rev

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

Rev 1 Rev 40
Line 27... Line 27...
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>
-
 
33
 
32
 
34
 
33
static char digits[] = "0123456789abcdef";
35
static char digits[] = "0123456789abcdef";
34
static spinlock_t printflock;
36
static spinlock_t printflock;
35
 
37
 
36
void print_str(char *str)
38
void print_str(char *str)
Line 77... Line 79...
77
 * It's much simpler than the user-space one.
79
 * It's much simpler than the user-space one.
78
 * We are greateful for this function.
80
 * We are greateful for this function.
79
 */
81
 */
80
void printf(char *fmt, ...)
82
void printf(char *fmt, ...)
81
{
83
{
82
    int irqpri, i = 0, pos = 0;
84
    int irqpri, i = 0;
-
 
85
    va_list ap;
83
    char c;
86
    char c;
-
 
87
 
-
 
88
    va_start(ap, fmt);
84
 
89
 
85
    irqpri = cpu_priority_high();
90
    irqpri = cpu_priority_high();
86
    spinlock_lock(&printflock);
91
    spinlock_lock(&printflock);
-
 
92
 
87
    while (c = fmt[i++]) {
93
    while (c = fmt[i++]) {
88
        switch (c) {
94
        switch (c) {
89
 
95
 
90
            /* control character */
96
            /* control character */
91
            case '%':
97
            case '%':
Line 97... Line 103...
97
 
103
 
98
                /*
104
                /*
99
                 * String and character conversions.
105
                 * String and character conversions.
100
                 */
106
                 */
101
                case 's':
107
                case 's':
102
                    print_str((char *) *(((__address *) &fmt + (++pos))));
108
                    print_str(va_arg(ap, char_ptr));
103
                    goto loop;
109
                    goto loop;
104
 
110
 
105
                case 'c':
111
                case 'c':
106
                    c = *((char *) ((__address *)(&fmt + (++pos))));
112
                    c = va_arg(ap, char);
107
                    break;
113
                    break;
108
 
114
 
109
                /*
115
                /*
110
                         * Hexadecimal conversions with fixed width.
116
                         * Hexadecimal conversions with fixed width.
111
                         */
117
                         */
112
                case 'L':
118
                case 'L':
113
                    print_str("0x");
119
                    print_str("0x");
114
                case 'l':
120
                case 'l':
115
                        print_fixed_hex(*((__address *)(&fmt + (++pos))),INT32);
121
                        print_fixed_hex(va_arg(ap, __native), INT32);
116
                    goto loop;
122
                    goto loop;
117
 
123
 
118
                case 'W':
124
                case 'W':
119
                    print_str("0x");
125
                    print_str("0x");
120
                case 'w':
126
                case 'w':
121
                        print_fixed_hex(*((__address *)(&fmt + (++pos))),INT16);
127
                        print_fixed_hex(va_arg(ap, __native), INT16);
122
                    goto loop;
128
                    goto loop;
123
 
129
 
124
                case 'B':
130
                case 'B':
125
                    print_str("0x");
131
                    print_str("0x");
126
                case 'b':
132
                case 'b':
127
                        print_fixed_hex(*((__address *)(&fmt + (++pos))),INT8);
133
                        print_fixed_hex(va_arg(ap, __native), INT8);
128
                    goto loop;
134
                    goto loop;
129
 
135
 
130
                /*
136
                /*
131
                         * Decimal and hexadecimal conversions.
137
                         * Decimal and hexadecimal conversions.
132
                         */
138
                         */
133
                case 'd':
139
                case 'd':
134
                        print_number(*((__address *)(&fmt + (++pos))), 10);
140
                        print_number(va_arg(ap, __native), 10);
135
                    goto loop;
141
                    goto loop;
136
 
142
 
137
                case 'X':
143
                case 'X':
138
                            print_str("0x");
144
                            print_str("0x");
139
                case 'x':
145
                case 'x':
140
                        print_number(*((__address *)(&fmt + (++pos))), 16);
146
                        print_number(va_arg(ap, __native), 16);
141
                    goto loop;
147
                    goto loop;
142
       
148
       
143
                /*
149
                /*
144
                 * Bad formatting.
150
                 * Bad formatting.
145
                 */
151
                 */
Line 155... Line 161...
155
    }
161
    }
156
 
162
 
157
out:
163
out:
158
    spinlock_unlock(&printflock);
164
    spinlock_unlock(&printflock);
159
    cpu_priority_restore(irqpri);
165
    cpu_priority_restore(irqpri);
-
 
166
   
-
 
167
    va_end(ap);
160
}
168
}