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

Function do_diff

util/msrtool/msrtool.c:188–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186}
187
188int do_diff(const char *difffn) {
189 char tmpfn[20], line[512], *m1start, *m2start;
190 size_t len;
191 int ret = 1, tmp, m1pos, sys_opened = 0;
192 FILE *fin = NULL, *fout = stdout;
193 uint8_t rev = 0;
194 uint32_t addr, linenum;
195 struct msr m1 = MSR1(0), m2 = MSR1(0);
196
197 if (':' == difffn[0]) {
198 rev = 1;
199 ++difffn;
200 }
201 if (0 == strcmp(difffn, "-"))
202 fin = stdin;
203 else if (NULL == (fin = fopen(difffn, "r"))) {
204 perror("fopen()");
205 return 1;
206 }
207
208 for (linenum = 1; NULL != fgets(line, sizeof(line), fin); ++linenum) {
209 tmp = strncmp("0x", line, 2) ? 0 : 2;
210 if (sscanf(line + tmp, "%8x %n%*x", &addr, &m1pos) < 1)
211 continue;
212 m1start = line + tmp + m1pos;
213 for (len = strlen(m1start) - 1; NULL != strchr("\r\n", m1start[len]); --len)
214 m1start[len] = 0;
215 if (!str2msr(m1start, &m1, &m2start)) {
216 fprintf(stderr, "%s:%d: invalid MSR1 value '%s'\n", difffn, linenum, m1start);
217 continue;
218 }
219 while (' ' == *m2start)
220 ++m2start;
221 if (!str2msr(m2start, &m2, NULL)) {
222 fprintf(stderr, "%s:%d: invalid MSR2 value '%s' - reading from hardware!\n", difffn, linenum, m2start);
223 if (!sys_opened) {
224 if (!found_system())
225 goto done;
226 sys_opened = sys->open(cpu, SYS_RDONLY);
227 if (!sys_opened)
228 goto done;
229 }
230 if (!sys->rdmsr(cpu, addr, &m2))
231 goto done;
232 }
233 if (diff_msr(fout, addr, rev ? m2 : m1, rev ? m1 : m2))
234 fprintf(fout, "\n");
235 }
236 if (!feof(fin))
237 fprintf(stderr, "%s:%d: fgets: %s\n", difffn, linenum, strerror(errno));
238 else
239 ret = 0;
240done:
241 if (sys_opened)
242 sys->close(cpu);
243 if (strcmp(difffn, "-")) {
244 if (ret)
245 unlink(tmpfn);

Callers 1

mainFunction · 0.85

Calls 12

fopenFunction · 0.85
perrorFunction · 0.85
strlenFunction · 0.85
str2msrFunction · 0.85
fprintfFunction · 0.85
found_systemFunction · 0.85
diff_msrFunction · 0.85
strerrorFunction · 0.85
fcloseFunction · 0.85
strcmpFunction · 0.50
strncmpFunction · 0.50
strchrFunction · 0.50

Tested by

no test coverage detected