Author: stuge
Date: 2010-01-17 19:33:53 +0100 (Sun, 17 Jan 2010)
New Revision: 5032

Modified:
   trunk/util/msrtool/msrtool.c
   trunk/util/msrtool/msrtool.h
   trunk/util/msrtool/msrutils.c
Log:
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 <pe...@stuge.se>
Acked-by: Stefan Reinauer <ste...@coresystems.de>


Modified: trunk/util/msrtool/msrtool.c
===================================================================
--- trunk/util/msrtool/msrtool.c        2010-01-17 14:08:17 UTC (rev 5031)
+++ trunk/util/msrtool/msrtool.c        2010-01-17 18:33:53 UTC (rev 5032)
@@ -208,7 +208,7 @@
                m1start = line + tmp + m1pos;
                for (len = strlen(m1start) - 1; NULL != strchr("\r\n", 
m1start[len]); --len)
                        m1start[len] = 0;
-               if (!str2msr(m1start, &m1)) {
+               if (!str2msr(m1start, &m1, NULL)) {
                        fprintf(stderr, "%s:%d: invalid MSR value '%s'\n", 
difffn, linenum, m1start);
                        continue;
                }
@@ -288,7 +288,7 @@
                                fprintf(stderr, "missing value in -i 
argument!\n");
                                break;
                        }
-                       if (!str2msr(++optarg, &msrval))
+                       if (!str2msr(++optarg, &msrval, NULL))
                                fprintf(stderr, "invalid value in -i 
argument!\n");
                        break;
                case 's':

Modified: trunk/util/msrtool/msrtool.h
===================================================================
--- trunk/util/msrtool/msrtool.h        2010-01-17 14:08:17 UTC (rev 5031)
+++ trunk/util/msrtool/msrtool.h        2010-01-17 18:33:53 UTC (rev 5032)
@@ -170,7 +170,7 @@
 uint32_t msraddrbyname(const char *name);
 void dumpmsrdefs(const struct targetdef *t);
 int dumpmsrdefsvals(FILE *f, const struct targetdef *t, const uint8_t cpu);
-uint8_t str2msr(char *str, struct msr *msr);
+uint8_t str2msr(char *str, struct msr *msr, char **endptr);
 void decodemsr(const uint8_t cpu, const uint32_t addr, const struct msr val);
 uint8_t diff_msr(FILE *fout, const uint32_t addr, const struct msr a, const 
struct msr b);
 

Modified: trunk/util/msrtool/msrutils.c
===================================================================
--- trunk/util/msrtool/msrutils.c       2010-01-17 14:08:17 UTC (rev 5031)
+++ trunk/util/msrtool/msrutils.c       2010-01-17 18:33:53 UTC (rev 5032)
@@ -193,7 +193,7 @@
  * 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 @@
  * @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 @@
                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;
 }
 


-- 
coreboot mailing list: coreboot@coreboot.org
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to