ref: 27a93fee9de975149493a9a8b3cab94ed1c8df25
parent: d70003df03613f39bcb8db0c0ecca0fcb1d5b58f
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Wed Jan 13 13:02:17 EST 2021
add msr.c
--- a/README.md
+++ b/README.md
@@ -4,3 +4,4 @@
Just copy and use for whatever you want.
* `qt.[ch]` [QP tries](https://dotat.at/prog/qp/README.html)
+* `msr.c` MSR reading tool
--- /dev/null
+++ b/msr.c
@@ -1,0 +1,32 @@
+#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);
+}