shithub: snippets

ref: 27a93fee9de975149493a9a8b3cab94ed1c8df25
dir: /msr.c/

View raw version
#include <u.h>
#include <libc.h>

static void
usage(void)
{
	fprint(2, "%s REGISTER\n", argv0);
	exits("usage");
}

void
main(int argc, char **argv)
{
	uvlong x, off;
	int f;

	ARGBEGIN{
	}ARGEND

	if(argc < 1)
		usage();

	if((f = open("/dev/msr", OREAD)) < 0)
		sysfatal("%r");
	off = strtoull(argv[0], nil, 0);
	if(pread(f, &x, 8, off) != 8)
		sysfatal("%r");
	close(f);
	print("%#llux\n", x);

	exits(nil);
}