diff options
author | Pekka Enberg <penberg@cs.helsinki.fi> | 2010-07-11 04:06:57 -0400 |
---|---|---|
committer | H. Peter Anvin <hpa@linux.intel.com> | 2010-07-12 17:46:00 -0400 |
commit | fa97bdf92709adaaf8b9a5164a895e262a4fcf60 (patch) | |
tree | e34f1b6232c302e39065f3dd7ef8bbf4c8ac3d3d /arch/x86/boot/string.c | |
parent | 589643be6693c46fbc54bae77745f336c8ed4bcc (diff) |
x86, setup: Early-boot serial I/O support
This patch adds serial I/O support to the real-mode setup (very early
boot) printf(). It's useful for debugging boot code when running Linux
under KVM, for example. The actual code was lifted from early printk.
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
LKML-Reference: <1278835617-11368-1-git-send-email-penberg@cs.helsinki.fi>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'arch/x86/boot/string.c')
-rw-r--r-- | arch/x86/boot/string.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c index f94b7a0c2abf..aba29df4a7bb 100644 --- a/arch/x86/boot/string.c +++ b/arch/x86/boot/string.c | |||
@@ -30,6 +30,22 @@ int strcmp(const char *str1, const char *str2) | |||
30 | return 0; | 30 | return 0; |
31 | } | 31 | } |
32 | 32 | ||
33 | int strncmp(const char *cs, const char *ct, size_t count) | ||
34 | { | ||
35 | unsigned char c1, c2; | ||
36 | |||
37 | while (count) { | ||
38 | c1 = *cs++; | ||
39 | c2 = *ct++; | ||
40 | if (c1 != c2) | ||
41 | return c1 < c2 ? -1 : 1; | ||
42 | if (!c1) | ||
43 | break; | ||
44 | count--; | ||
45 | } | ||
46 | return 0; | ||
47 | } | ||
48 | |||
33 | size_t strnlen(const char *s, size_t maxlen) | 49 | size_t strnlen(const char *s, size_t maxlen) |
34 | { | 50 | { |
35 | const char *es = s; | 51 | const char *es = s; |
@@ -48,3 +64,28 @@ unsigned int atou(const char *s) | |||
48 | i = i * 10 + (*s++ - '0'); | 64 | i = i * 10 + (*s++ - '0'); |
49 | return i; | 65 | return i; |
50 | } | 66 | } |
67 | |||
68 | /* Works only for digits and letters, but small and fast */ | ||
69 | #define TOLOWER(x) ((x) | 0x20) | ||
70 | |||
71 | unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base) | ||
72 | { | ||
73 | unsigned long long result = 0; | ||
74 | |||
75 | if (base == 16 && cp[0] == '0' && TOLOWER(cp[1]) == 'x') | ||
76 | cp += 2; | ||
77 | |||
78 | while (isxdigit(*cp)) { | ||
79 | unsigned int value; | ||
80 | |||
81 | value = isdigit(*cp) ? *cp - '0' : TOLOWER(*cp) - 'a' + 10; | ||
82 | if (value >= base) | ||
83 | break; | ||
84 | result = result * base + value; | ||
85 | cp++; | ||
86 | } | ||
87 | if (endp) | ||
88 | *endp = (char *)cp; | ||
89 | |||
90 | return result; | ||
91 | } | ||