github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/cmds/core/msr/doc_linux.go (about) 1 // Copyright 2018-2020 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // msr -- read and write MSRs with regular command or Forth 6 // 7 // Synopsis: 8 // 9 // msr [OPTIONS] r glob MSR 10 // msr [OPTIONS] w glob MSR value 11 // msr [OPTIONS] forth-word [forth-word ...] 12 // 13 // Description: 14 // 15 // This program reads and writes sets of MSRs, while allowing 16 // them to by changed on a core by core or collective basis. 17 // 18 // To read the msrs for 0 (sorry, the command is msr and the forth command 19 // is msr, making this a bit confusing): 20 // sudo msr 0 msr 0x3a reg rd 21 // Breaking that down: 22 // 0 - for cpu 0 23 // msr - for take the glob, in this case 0, and push all matching filenames on the stack 24 // 0x3a - for register 0x3a 25 // reg - convert to 32-bit integer and push 26 // rd - pop a 32-bit int and a []string and use them to read 1 or more MSRs 27 // 28 // for all: 29 // sudo msr "'*" msr 0x3a reg rd 30 // 31 // The "'" is needed to quote the * so forth does not think we're multiplying. 32 // 33 // Here is a breakdown, running msr with each command in turn: 34 // rminnich@xcpu:~/gopath/src/github.com/mvdan/u-root-coreutils/cmds/core/msr$ ./msr 0 35 // 0 36 // rminnich@xcpu:~/gopath/src/github.com/mvdan/u-root-coreutils/cmds/core/msr$ ./msr 0 msr 37 // [/dev/cpu/0/msr] 38 // rminnich@xcpu:~/gopath/src/github.com/mvdan/u-root-coreutils/cmds/core/msr$ ./msr 0 msr 0x3a 39 // [[/dev/cpu/0/msr] 0x3a] 40 // rminnich@xcpu:~/gopath/src/github.com/mvdan/u-root-coreutils/cmds/core/msr$ ./msr 0 msr 0x3a reg 41 // [[/dev/cpu/0/msr] 58] 42 // rminnich@xcpu:~/gopath/src/github.com/mvdan/u-root-coreutils/cmds/core/msr$ ./msr 0 msr 0x3a reg rd 43 // [0] 44 // rminnich@xcpu:~/gopath/src/github.com/mvdan/u-root-coreutils/cmds/core/msr$ 45 // 46 // To read, then write all of them 47 // (the dup is so we have the msr list at TOS -- it's just a convenience) 48 // sudo msr 0 msr dup 0x3a reg rd 0x3a reg swap 1 u64 or wr 49 // to just write them 50 // 51 // Also, note, all the types are checked by assertions. The reg has to be 52 // 32 bits, the val 64 53 // 54 // more examples: 55 // read reg 0x3a and leave the least of MSRs and values on TOS, to be 56 // printed at exit. 57 // 58 // sudo msr "'"* msr dup 0x3a reg rd 59 // [[/dev/cpu/0/msr /dev/cpu/1/msr /dev/cpu/2/msr /dev/cpu/3/msr] [5 5 5 5]] 60 // 61 // From there, the write is easy: 62 // sudo msr "'"* msr dup 0x3a reg rd 0x3a reg swap wr 63 // 64 // For convenience, we maintain the old read and write commands: 65 // msr r <glob> <register> 66 // msr w <glob> <register> <value> 67 // 68 // Yep, it's a bit inconvenient; the idea is that in the simple case, 69 // you will use the r and w commands. For programmatic cases, you can 70 // work to build up a working set of arguments. 71 // 72 // For example, I started with 73 // msr "'"* msr 74 // and, once I saw the MSR selection was OK, built the command up from 75 // there. At each step I could see the stack and whether I was going the 76 // right direction. 77 // 78 // The old commands remain: 79 // rminnich@xcpu:~/gopath/src/github.com/mvdan/u-root-coreutils/cmds/core/msr$ sudo ./msr r 0 0x3a 80 // [5] 81 // rminnich@xcpu:~/gopath/src/github.com/mvdan/u-root-coreutils/cmds/core/msr$ sudo ./msr w 0 0x3a 5 82 // [5] 83 // 84 // For a view of what Forth is doing, run with -d. 85 package main