annotate cos/kernel/snprintf.c @ 18:6129643f5c34

Fixed interrupt issue, ds, es, ss, fs and gs were not initialized to 0
author windel
date Sun, 20 Nov 2011 20:35:51 +0100
parents f3e3e0e9c4bc
children 8012221dd740
rev   line source
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
1 /*
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
2 * snprintf.c
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
3 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
4 #include "kernel.h"
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
5
13
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
6 /*
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
7 * NOTE! This ctype does not handle EOF like the standard C
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
8 * library is required to.
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
9 */
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
10
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
11 #define _U 0x01 /* upper */
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
12 #define _L 0x02 /* lower */
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
13 #define _D 0x04 /* digit */
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
14 #define _C 0x08 /* cntrl */
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
15 #define _P 0x10 /* punct */
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
16 #define _S 0x20 /* white space (space/lf/tab) */
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
17 #define _X 0x40 /* hex digit */
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
18 #define _SP 0x80 /* hard space (0x20) */
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
19
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
20
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 13
diff changeset
21 uint8_t _ctype[] = {
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
22 _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
23 _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
24 _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
25 _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
26 _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
27 _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
28 _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
29 _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
30 _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
31 _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
32 _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
33 _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
34 _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
35 _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
36 _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
37 _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
38 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
39 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
40 _S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 160-175 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
41 _P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 176-191 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
42 _U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U, /* 192-207 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
43 _U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L, /* 208-223 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
44 _L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L, /* 224-239 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
45 _L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L}; /* 240-255 */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
46
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 13
diff changeset
47 #define __ismask(x) (_ctype[(int)(uint8_t)(x)])
13
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
48
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
49 #define isalnum(c) ((__ismask(c)&(_U|_L|_D)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
50 #define isalpha(c) ((__ismask(c)&(_U|_L)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
51 #define iscntrl(c) ((__ismask(c)&(_C)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
52 #define isdigit(c) ((__ismask(c)&(_D)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
53 #define isgraph(c) ((__ismask(c)&(_P|_U|_L|_D)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
54 #define islower(c) ((__ismask(c)&(_L)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
55 #define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
56 #define ispunct(c) ((__ismask(c)&(_P)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
57 #define isspace(c) ((__ismask(c)&(_S)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
58 #define isupper(c) ((__ismask(c)&(_U)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
59 #define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
60
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
61 #define isascii(c) (((unsigned char)(c))<=0x7f)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
62 #define toascii(c) (((unsigned char)(c))&0x7f)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
63
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 13
diff changeset
64 static inline uint8_t tolower(uint8_t c)
13
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
65 {
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
66 if (isupper(c))
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
67 c -= 'A'-'a';
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
68 return c;
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
69 }
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
70
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 13
diff changeset
71 static inline uint8_t toupper(uint8_t c)
13
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
72 {
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
73 if (islower(c))
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
74 c -= 'a'-'A';
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
75 return c;
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
76 }
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
77
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
78 #define MORE_THAN_YOU_WANT 1<<30
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
79 #define MAX_STDOUT_CHARS 255
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
80
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
81 static char hexmap[] = {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
82 '0', '1', '2', '3', '4', '5', '6', '7',
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
83 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
84 };
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
85
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
86 void va_snprintf(char *b, int l, const char *fmt, va_list pvar)
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
87 {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
88 int n, i;
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 13
diff changeset
89 uint32_t u;
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 13
diff changeset
90 uint64_t ull;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
91 char *t;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
92 char d[10];
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
93 char mod_l;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
94 char mod_ll;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
95
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
96 if (!fmt || !b || (l < 1))
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
97 return;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
98
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
99 mod_l = 0;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
100 mod_ll = 0;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
101
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
102 while (l && *fmt) {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
103 if (*fmt == '%') {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
104 if (!(--l))
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
105 break;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
106 again:
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
107 fmt++;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
108
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
109 switch (*fmt) {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
110 case '.': /* precision modifier */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
111 while(isdigit(fmt[1]))
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
112 fmt++;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
113 goto again;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
114
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
115 case 'l': /* long modifier */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
116 if (!mod_l) {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
117 mod_l = 1;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
118 } else if (!mod_ll) {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
119 mod_l = 0;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
120 mod_ll = 1;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
121 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
122 goto again;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
123
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
124 case 's': /* string */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
125 t = va_arg(pvar, char *);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
126 while (l && *t)
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
127 *b++ = *t++, l--;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
128 break;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
129
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
130 case 'c': /* single character */
18
6129643f5c34 Fixed interrupt issue, ds, es, ss, fs and gs were not initialized to 0
windel
parents: 17
diff changeset
131 *b++ = (char)va_arg(pvar, int);
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
132 l--;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
133 break;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
134
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
135 case 'S': /* uint32 as a short ... */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
136 if (l < 4) {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
137 l = 0;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
138 break;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
139 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
140 u = va_arg(pvar, unsigned int);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
141 for (i = 3; i >= 0; i--) {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
142 b[i] = hexmap[u & 0x0F];
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
143 u >>= 4;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
144 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
145 b += 4;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
146 l -= 4;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
147 break;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
148
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
149 case 'x':
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
150 case 'p':
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
151 if (!mod_ll) { /* 8 digit, unsigned 32-bit hex integer */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
152 if (l < 8) {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
153 l = 0;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
154 break;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
155 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
156 u = va_arg(pvar, unsigned int);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
157 for (i = 7; i >= 0; i--) {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
158 b[i] = hexmap[u & 0x0F];
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
159 u >>= 4;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
160 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
161 b += 8;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
162 l -= 8;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
163 } else if (mod_ll) { /* 16 digit, unsigned 64-bit hex integer */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
164 if (l < 16) {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
165 l = 0;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
166 break;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
167 }
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 13
diff changeset
168 ull = va_arg(pvar, uint64_t);
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
169 for (i = 15; i >= 0; i--) {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
170 b[i] = hexmap[ull & 0x0f];
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
171 ull >>= 4;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
172 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
173 b += 16;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
174 l -= 16;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
175 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
176 mod_l = mod_ll = 0;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
177 break;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
178
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
179 case 'd': /* signed integer */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
180 n = va_arg(pvar, int);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
181 if (n < 0) {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
182 u = -n;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
183 *b++ = '-';
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
184 if (!(--l))
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
185 break;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
186 } else {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
187 u = n;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
188 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
189 goto u2;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
190
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
191 case 'u': /* unsigned integer */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
192 u = va_arg(pvar, unsigned int);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
193 u2:
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
194 i = 9;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
195 do {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
196 d[i] = (u % 10) + '0';
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
197 u /= 10;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
198 i--;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
199 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
200 while (u && i >= 0);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
201 while (++i < 10) {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
202 *b++ = d[i];
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
203 if (!(--l))
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
204 break;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
205 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
206 break;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
207
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
208 case 'U':
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
209 u = va_arg(pvar, unsigned int);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
210 i = 9;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
211 d[8] = d[7] = d[6] = ' ';
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
212 do {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
213 d[i] = (u % 10) + '0';
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
214 u /= 10;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
215 i--;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
216 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
217 while (u && i >= 0);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
218 i = 5;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
219 while (++i < 10) {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
220 *b++ = d[i];
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
221 if (!(--l))
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
222 break;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
223 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
224 break;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
225
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
226 case 'X': /* 2 digit, unsigned 8bit hex int */
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
227 if (l < 2) {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
228 l = 0;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
229 break;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
230 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
231 n = va_arg(pvar, int);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
232 *b++ = hexmap[(n & 0xF0) >> 4];
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
233 *b++ = hexmap[n & 0x0F];
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
234 l -= 2;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
235 break;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
236 default:
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
237 *b++ = *fmt;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
238 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
239 } else {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
240 *b++ = *fmt;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
241 l--;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
242 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
243 fmt++;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
244 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
245 *b = 0;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
246 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
247
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
248 void snprintf(char *str, int len, char *fmt, ...)
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
249 {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
250 va_list pvar;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
251 va_start(pvar, fmt);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
252 va_snprintf(str, len, fmt, pvar);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
253 va_end(pvar);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
254 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
255
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
256 void
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
257 sprintf(char *dst, const char *fmt, ...)
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
258 {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
259 va_list args;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
260 va_start(args, fmt);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
261 va_snprintf(dst, MORE_THAN_YOU_WANT, fmt, args);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
262 va_end(args);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
263 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
264
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
265 void
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
266 printf(const char* fmt, ...)
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
267 {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
268 static char buf[MAX_STDOUT_CHARS];
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
269
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
270 va_list args;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
271 va_start(args, fmt);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
272 va_snprintf(buf, MAX_STDOUT_CHARS, fmt, args);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
273 va_end(args);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
274
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
275 print_string(buf);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
276 }