diff options
author | Peter Stuge <peter@stuge.se> | 2010-01-17 18:33:53 +0000 |
---|---|---|
committer | Peter Stuge <peter@stuge.se> | 2010-01-17 18:33:53 +0000 |
commit | 34f2907a1b969270e92281849cfdfc43c343799c (patch) | |
tree | ff4562be914b01b10e9fdda313f7d97d90140705 /util/msrtool/msrutils.c | |
parent | 838c5a5d8019eff857dac21c24a2bca624fa3152 (diff) | |
download | coreboot-34f2907a1b969270e92281849cfdfc43c343799c.tar.xz |
msrtool: Add endptr to str2msr() showing how many characters were parsed
This also introduces a small change in the user interface for immediate
mode (-i). Previously, whitespace could separate high and low words in
an MSR as such:
msrtool -i 4c00000f='f2f100ff 56960004'
That is no longer allowed, a space character now ends the MSR value. Any
other character can still be used as separator however, so the following
syntax still works as expected:
msrtool -i 4c00000f=f2f100ff:56960004
Signed-off-by: Peter Stuge <peter@stuge.se>
Acked-by: Stefan Reinauer <stepan@coresystems.de>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@5032 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util/msrtool/msrutils.c')
-rw-r--r-- | util/msrtool/msrutils.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/util/msrtool/msrutils.c b/util/msrtool/msrutils.c index dfb66178f6..5a5fbd806b 100644 --- a/util/msrtool/msrutils.c +++ b/util/msrtool/msrutils.c @@ -193,7 +193,7 @@ int dumpmsrdefsvals(FILE *f, const struct targetdef *t, const uint8_t cpu) { * Parse a hexadecimal string into an MSR value. * * Leading 0x or 0X is optional, the string is always parsed as hexadecimal. - * Any non-hexadecimal character can be used to separate the high 32 bits and + * Any non-hexadecimal character except ' ' can separate the high 32 bits and * the low 32 bits. If there is such a separator, high and low values do not * need to be zero padded. If there is no separator, the last <=8 digits are * the low 32 bits and any characters before them are the high 32 bits. @@ -205,15 +205,16 @@ int dumpmsrdefsvals(FILE *f, const struct targetdef *t, const uint8_t cpu) { * @param str The string to parse. The string must be writable but will be * restored before return. * @param msr Pointer to the struct msr where the value will be stored. + * @param endptr If endpotr is not NULL, *endptr will point to after the MSR. * @return 1 on success, 0 on parse failure. msr is unchanged on failure. */ -uint8_t str2msr(char *str, struct msr *msr) { +uint8_t str2msr(char *str, struct msr *msr, char **endptr) { char c; size_t len, lo; if (0 == strncmp(str, "0x", 2) || 0 == strncmp(str, "0X", 2)) str += 2; len = strspn(str, HEXCHARS); - if (len <= 8 && 0 == str[len]) { + if (len <= 8 && (0 == str[len] || ' ' == str[len])) { msr->hi = 0; lo = 0; } else if (len <= 8) { @@ -231,7 +232,7 @@ uint8_t str2msr(char *str, struct msr *msr) { msr->hi = strtoul(str, NULL, 16); str[lo] = c; } - msr->lo = strtoul(str + lo, NULL, 16); + msr->lo = strtoul(str + lo, endptr, 16); return 1; } |