This program:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
main (int argc, char *argv[])
{
unsigned char buf[8], *p;
int fd_msr, i;
unsigned long addr = 0;
if (argc < 3) {
printf("usage:wrmsr reg value\n");
exit(1);
}
addr = strtoul(argv[1], NULL, 0);
p = argv[2];
printf("MSR register 0x%lx => ", addr);
for (i = 7; i > 0; i--) {
buf[i] = strtol(p, &p, 16);
p++;
printf("%2.2x:", buf[i]);
}
buf[i] = strtol(p, &p, 16);
printf("%2.2x\n", buf[i]);
fd_msr = open("/dev/cpu/0/msr", O_WRONLY);
lseek(fd_msr, addr, SEEK_SET);
if (write(fd_msr, buf, 8) < 0)
perror("");
}
compiles to a 512KB binary on linux with -static
Well, *I'm* impressed anyway.
[[ standard old guy story about "my first Unix box" and "nobody knows
the value of 2 bits anymore" and "what's with these GNU kids today"
deleted -- ed.]]
yy* symbols are in there btw. And, don't worry, some pthreads symbols
made it in as well. Don't want main() to be too lonely!
ron