forked from mpollice/AmdMsrTweaker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWinRing0.h
49 lines (36 loc) · 1.2 KB
/
WinRing0.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright (c) Martin Kinkelin
*
* See the "License.txt" file in the root directory for infos
* about permitted and prohibited uses of this code.
*/
#pragma once
#define WIN32_MEAN_AND_LEAN
#include <windows.h>
#undef min
#undef max
#include "WinRing0/OlsApi.h"
typedef unsigned long long QWORD;
struct CpuidRegs
{
DWORD eax;
DWORD ebx;
DWORD ecx;
DWORD edx;
};
static const DWORD AMD_CPU_DEVICE = 0x18; // first AMD CPU
DWORD ReadPciConfig(DWORD device, DWORD function, DWORD regAddress);
void WritePciConfig(DWORD device, DWORD function, DWORD regAddress, DWORD value);
QWORD Rdmsr(DWORD index);
void Wrmsr(DWORD index, const QWORD& value);
CpuidRegs Cpuid(DWORD index);
template <typename T> DWORD GetBits(T value, unsigned char offset, unsigned char numBits)
{
const T mask = (((T)1 << numBits) - (T)1); // 2^numBits - 1; after right-shift
return (DWORD)((value >> offset) & mask);
}
template <typename T> void SetBits(T& value, DWORD bits, unsigned char offset, unsigned char numBits)
{
const T mask = (((T)1 << numBits) - (T)1) << offset; // 2^numBits - 1, shifted by offset to the left
value = (value & ~mask) | (((T)bits << offset) & mask);
}