MCPcopy Create free account
hub / github.com/coreboot/coreboot / str2msr

Function str2msr

util/msrtool/msrutils.c:238–264  ·  view source on GitHub ↗

* 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 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 be

Source from the content-addressed store, hash-verified

236 * @return 1 on success, 0 on parse failure. msr is unchanged on failure.
237 */
238uint8_t str2msr(char *str, struct msr *msr, char **endptr) {
239 char c;
240 size_t len, lo;
241 if (0 == strncmp(str, "0x", 2) || 0 == strncmp(str, "0X", 2))
242 str += 2;
243 len = strspn(str, HEXCHARS);
244 if (len <= 8 && (0 == str[len] || ' ' == str[len])) {
245 msr->hi = 0;
246 lo = 0;
247 } else if (len <= 8) {
248 lo = len + strcspn(str + len, HEXCHARS);
249 if (0 == len && 0 == strspn(str + lo, HEXCHARS))
250 return 0;
251 c = str[len];
252 str[len] = 0;
253 msr->hi = strtoul(str, NULL, 16);
254 str[len] = c;
255 } else {
256 lo = len - 8;
257 c = str[lo];
258 str[lo] = 0;
259 msr->hi = strtoul(str, NULL, 16);
260 str[lo] = c;
261 }
262 msr->lo = strtoul(str + lo, endptr, 16);
263 return 1;
264}
265
266void decodemsr(const uint8_t cpu, const uint32_t addr, const struct msr val) {
267 struct msr bitval, mask;

Callers 2

do_diffFunction · 0.85
mainFunction · 0.85

Calls 4

strncmpFunction · 0.50
strspnFunction · 0.50
strcspnFunction · 0.50
strtoulFunction · 0.50

Tested by

no test coverage detected