akaros/tests/wrmsr.c
<<
>>
Prefs
   1/* Copyright (c) 2016 Google Inc.
   2 * Barret Rhoden <brho@cs.berkeley.edu>
   3 * See LICENSE for details.
   4 *
   5 * Usage: wrmsr MSR VAL
   6 *
   7 * This will write VAL to *all cores* MSR.
   8 *
   9 * e.g. wrmsr 0x199 0x100002600 */
  10
  11#include <stdio.h>
  12#include <stdlib.h>
  13#include <stdint.h>
  14#include <sys/types.h>
  15#include <sys/stat.h>
  16#include <fcntl.h>
  17#include <assert.h>
  18#include <unistd.h>
  19
  20int main(int argc, char **argv)
  21{
  22        uint32_t msr;
  23        uint64_t val;
  24        int fd;
  25        ssize_t ret;
  26
  27        if (argc < 3) {
  28                printf("Usage: %s MSR VAL\n", argv[0]);
  29                exit(-1);
  30        }
  31        msr = strtoul(argv[1], 0, 0);
  32        val = strtoul(argv[2], 0, 0);
  33
  34        fd = open("#arch/msr", O_RDWR);
  35        if (fd < 0) {
  36                perror("open");
  37                exit(-1);
  38        }
  39        ret = pwrite(fd, &val, sizeof(val), msr);
  40        if (ret < 0) {
  41                perror("pwrite");
  42                exit(-1);
  43        }
  44        return 0;
  45}
  46