annotate cos/kernel/snprintf.c @ 383:173e20a47fda

Added linker description loader
author Windel Bouwman
date Sun, 27 Apr 2014 17:40:39 +0200
parents 8012221dd740
children
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
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 13
diff changeset
20 uint8_t _ctype[] = {
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
21 _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
22 _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
23 _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
24 _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
25 _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
26 _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
27 _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
28 _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
29 _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
30 _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
31 _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
32 _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
33 _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
34 _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
35 _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
36 _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
37 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
38 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
39 _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
40 _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
41 _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
42 _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
43 _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
44 _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
45
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 13
diff changeset
46 #define __ismask(x) (_ctype[(int)(uint8_t)(x)])
13
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
47
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
48 #define isalnum(c) ((__ismask(c)&(_U|_L|_D)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
49 #define isalpha(c) ((__ismask(c)&(_U|_L)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
50 #define iscntrl(c) ((__ismask(c)&(_C)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
51 #define isdigit(c) ((__ismask(c)&(_D)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
52 #define isgraph(c) ((__ismask(c)&(_P|_U|_L|_D)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
53 #define islower(c) ((__ismask(c)&(_L)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
54 #define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
55 #define ispunct(c) ((__ismask(c)&(_P)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
56 #define isspace(c) ((__ismask(c)&(_S)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
57 #define isupper(c) ((__ismask(c)&(_U)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
58 #define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
59
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
60 #define isascii(c) (((unsigned char)(c))<=0x7f)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
61 #define toascii(c) (((unsigned char)(c))&0x7f)
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
62
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 13
diff changeset
63 static inline uint8_t tolower(uint8_t c)
13
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
64 {
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
65 if (isupper(c))
34
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
66 c += 'a'-'A';
13
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
67 return c;
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
68 }
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
69
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 13
diff changeset
70 static inline uint8_t toupper(uint8_t c)
13
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
71 {
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
72 if (islower(c))
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
73 c -= 'a'-'A';
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
74 return c;
d07d4701a103 Cleanup of header files
windel
parents: 12
diff changeset
75 }
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
76
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
77 #define MORE_THAN_YOU_WANT 1<<30
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
78 #define MAX_STDOUT_CHARS 255
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
79
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
80 static char hexmap[] = {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
81 '0', '1', '2', '3', '4', '5', '6', '7',
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
82 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
83 };
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
84
34
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
85 /* string print function. Supports the formats:
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
86 %p, %x: 64 bits hex number
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
87 %d: signed integer
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
88 %u: unsigned integer
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
89 */
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
90 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
91 {
34
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
92 int i;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
93 int64_t s64;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
94 uint64_t u64;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
95 char *t;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
96 char d[20]; // For storing the decimal value in chars.
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
97
34
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
98 if ((fmt == 0) || (b == 0) || (l < 1))
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
99 {
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
100 return;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
101 }
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
102
34
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
103 while ((l > 0) && (*fmt != 0))
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
104 {
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
105 if (*fmt == '%')
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
106 {
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
107 if ((--l) == 0)
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
108 {
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
109 break;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
110 }
34
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
111
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
112 fmt++;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
113 switch (*fmt)
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
114 {
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
115 case 's': /* string */
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
116 t = va_arg(pvar, char *);
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
117 while ((l > 0) && (*t != 0))
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
118 {
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
119 *b++ = *t++;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
120 l--;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
121 }
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
122 break;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
123
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
124 case 'c': /* single character */
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
125 *b++ = (char)va_arg(pvar, int);
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
126 l--;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
127 break;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
128
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
129 case 'x':
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
130 case 'p':
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
131 /* Pointer and hex uint64_t */
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
132 /* 16 digit, unsigned 64-bit hex integer */
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
133 if (l < 18)
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
134 {
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
135 l = 0;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
136 break;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
137 }
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
138
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
139 *b++ = '0';
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
140 *b++ = 'x';
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
141
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
142 u64 = va_arg(pvar, uint64_t);
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
143 for (i = 15; i >= 0; i--)
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
144 {
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
145 b[i] = hexmap[u64 & 0x0f];
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
146 u64 >>= 4;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
147 }
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
148 b += 16;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
149 l -= 16;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
150 break;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
151
34
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
152 case 'd': /* signed integer */
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
153 s64 = va_arg(pvar, int);
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
154 if (s64 < 0)
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
155 {
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
156 u64 = (uint64_t)(-s64);
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
157 *b++ = '-';
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
158 if ((--l) == 0)
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
159 {
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
160 break;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
161 }
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
162 }
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
163 else
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
164 {
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
165 u64 = s64;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
166 }
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
167 goto u2;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
168
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
169 case 'u': /* unsigned integer */
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
170 u64 = va_arg(pvar, unsigned int);
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
171 u2:
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
172 i = 19;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
173 do
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
174 {
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
175 d[i] = (u64 % 10) + '0';
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
176 u64 /= 10;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
177 i--;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
178 }
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
179 while ((u64 != 0) && (i >= 0));
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
180
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
181 // Now print the characters:
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
182 while (++i < 20)
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
183 {
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
184 *b++ = d[i];
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
185 if ((--l) == 0)
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
186 {
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
187 break;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
188 }
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
189 }
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
190 break;
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
191
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
192 default:
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
193 *b++ = *fmt;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
194 }
34
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
195 }
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
196 else
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
197 {
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
198 *b++ = *fmt;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
199 l--;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
200 }
34
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
201
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
202 fmt++;
34
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
203 }
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
204
8012221dd740 Fixes for uninitialized data. This causes problems on real machines
windel
parents: 18
diff changeset
205 *b = 0; // Add a 0 terminate
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
206 }
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 void snprintf(char *str, int len, char *fmt, ...)
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
209 {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
210 va_list pvar;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
211 va_start(pvar, fmt);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
212 va_snprintf(str, len, fmt, pvar);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
213 va_end(pvar);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
214 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
215
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
216 void
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
217 printf(const char* fmt, ...)
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
218 {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
219 static char buf[MAX_STDOUT_CHARS];
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
220
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
221 va_list args;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
222 va_start(args, fmt);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
223 va_snprintf(buf, MAX_STDOUT_CHARS, fmt, args);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
224 va_end(args);
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 print_string(buf);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
227 }