2 * Jailhouse, a Linux-based partitioning hypervisor
4 * Copyright (c) Siemens AG, 2013
7 * Jan Kiszka <jan.kiszka@siemens.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
13 #if BITS_PER_LONG < 64
15 static unsigned long long div_u64_u64(unsigned long long dividend,
16 unsigned long long divisor)
18 unsigned long long result = 0;
19 unsigned long long tmp_res, tmp_div;
21 while (dividend >= divisor) {
22 tmp_div = divisor << 1;
24 while (dividend >= tmp_div) {
28 dividend -= divisor * tmp_res;
34 #else /* BITS_PER_LONG >= 64 */
36 static inline unsigned long long div_u64_u64(unsigned long long dividend,
37 unsigned long long divisor)
39 return dividend / divisor;
42 #endif /* BITS_PER_LONG >= 64 */
44 static char *uint2str(unsigned long long value, char *buf)
46 unsigned long long digit, divisor = 10000000000000000000ULL;
50 digit = div_u64_u64(value, divisor);
51 value -= digit * divisor;
52 if (!first_digit || digit > 0 || divisor == 1) {
56 divisor = div_u64_u64(divisor, 10);
62 static char *int2str(long long value, char *buf)
68 return uint2str(value, buf);
71 static char *hex2str(unsigned long long value, char *buf,
72 unsigned long long leading_zero_mask)
74 const char hexdigit[] = "0123456789abcdef";
75 unsigned long long digit, divisor = 0x1000000000000000ULL;
79 digit = div_u64_u64(value, divisor);
80 value -= digit * divisor;
81 if (!first_digit || digit > 0 || divisor == 1 ||
82 divisor & leading_zero_mask) {
83 *buf++ = hexdigit[digit];
92 static char *align(char *p1, char *p0, unsigned long width)
99 for (n = 1; p1 - n >= p0; n++)
100 *(p0 + width - n) = *(p1 - n);
101 memset(p0, ' ', width - (p1 - p0));
105 static void __vprintk(const char *fmt, va_list ap)
110 unsigned long long v;
129 while (c >= '0' && c <= '9') {
130 width = width * 10 + c - '0';
132 if (width >= sizeof(buf) - 1)
145 v = va_arg(ap, long);
149 p = align(p, p0, width);
154 v = va_arg(ap, unsigned long);
155 p = hex2str(v, p, (unsigned long)-1);
158 console_write(va_arg(ap, const char *));
162 v = va_arg(ap, unsigned long);
164 v = va_arg(ap, unsigned int);
166 p = align(p, p0, width);
170 v = va_arg(ap, unsigned long);
172 v = va_arg(ap, unsigned int);
173 p = hex2str(v, p, 0);
174 p = align(p, p0, width);
181 } else if (c == '\n') {
190 if (p >= &buf[sizeof(buf) - 1]) {