| 68 | int msr_readerror = 0; |
| 69 | |
| 70 | static msr_t rdmsr(unsigned int addr) |
| 71 | { |
| 72 | uint32_t buf[2]; |
| 73 | msr_t msr = { 0xffffffff, 0xffffffff }; |
| 74 | |
| 75 | if (lseek(fd_msr, (off_t) addr, SEEK_SET) == -1) { |
| 76 | perror("Could not lseek() to MSR"); |
| 77 | close(fd_msr); |
| 78 | exit(1); |
| 79 | } |
| 80 | |
| 81 | if (read(fd_msr, buf, 8) == 8) { |
| 82 | msr.lo = buf[0]; |
| 83 | msr.hi = buf[1]; |
| 84 | return msr; |
| 85 | } |
| 86 | |
| 87 | if (errno == 5) { |
| 88 | printf(" (*)"); // Not all bits of the MSR could be read |
| 89 | msr_readerror = 1; |
| 90 | } else { |
| 91 | // A severe error. |
| 92 | perror("Could not read() MSR"); |
| 93 | close(fd_msr); |
| 94 | exit(1); |
| 95 | } |
| 96 | |
| 97 | return msr; |
| 98 | } |
| 99 | |
| 100 | static int open_and_seek(int cpu, unsigned long msr, int mode, int *fd) |
| 101 | { |
no test coverage detected