forked from sigma-1/directhw
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDirectHW.hpp
executable file
·154 lines (117 loc) · 3.9 KB
/
DirectHW.hpp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* DirectHW - Kernel extension to pass through IO commands to user space
*
* Copyright © 2008-2010 coresystems GmbH <[email protected]>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#define DIRECTHW_VERSION "1.3"
#define DIRECTHW_VERNUM 0x00100300
/* */
class DirectHWService:public IOService {
OSDeclareDefaultStructors(DirectHWService)
public:
virtual bool start(IOService * provider);
};
/* */
class DirectHWService;
class DirectHWUserClient:public IOUserClient {
OSDeclareDefaultStructors(DirectHWUserClient)
enum {
kReadIO,
kWriteIO,
kPrepareMap,
kReadMSR,
kWriteMSR,
kReadCpuId,
kReadMem,
kNumberOfMethods
};
typedef struct {
UInt32 offset;
UInt32 width;
UInt32 data;
} iomem_t;
typedef struct {
UInt64 addr;
UInt64 size;
} map_t;
typedef struct {
UInt32 core;
UInt32 index;
UInt32 hi;
UInt32 lo;
} msrcmd_t;
typedef struct {
uint32_t core;
uint32_t eax;
uint32_t ecx;
uint32_t output[4];
} cpuid_t;
typedef struct {
uint32_t core;
uint64_t addr;
uint32_t data;
} readmem_t;
public:
virtual bool initWithTask(task_t task, void *securityID, UInt32 type);
virtual bool start(IOService * provider);
virtual void stop(IOService * provider);
virtual IOReturn clientMemoryForType(UInt32 type, UInt32 *flags, IOMemoryDescriptor **memory);
virtual IOReturn clientClose(void);
protected:
DirectHWService * fProvider;
static const IOExternalMethod fMethods[kNumberOfMethods];
virtual IOExternalMethod * getTargetAndMethodForIndex(IOService ** target, UInt32 index);
virtual IOReturn ReadIO(iomem_t * inStruct, iomem_t * outStruct,
IOByteCount inStructSize,
IOByteCount * outStructSize);
virtual IOReturn WriteIO(iomem_t * inStruct, iomem_t * outStruct,
IOByteCount inStructSize,
IOByteCount * outStructSize);
virtual IOReturn PrepareMap(map_t * inStruct, map_t * outStruct,
IOByteCount inStructSize,
IOByteCount * outStructSize);
virtual IOReturn ReadMSR(msrcmd_t * inStruct, msrcmd_t * outStruct,
IOByteCount inStructSize,
IOByteCount * outStructSize);
virtual IOReturn WriteMSR(msrcmd_t * inStruct, msrcmd_t * outStruct,
IOByteCount inStructSize,
IOByteCount * outStructSize);
virtual IOReturn ReadCpuId(cpuid_t * inStruct, cpuid_t * outStruct,
IOByteCount inStructSize,
IOByteCount * outStructSize);
virtual IOReturn ReadMem(readmem_t * inStruct, readmem_t * outStruct,
IOByteCount inStructSize,
IOByteCount * outStructSize);
private:
task_t fTask;
UInt64 LastMapAddr, LastMapSize;
static void MSRHelperFunction(void *data);
static void CPUIDHelperFunction(void *data);
static void ReadMemHelperFunction(void *data);
typedef struct { msrcmd_t *in, *out; bool Read; } MSRHelper;
typedef struct { cpuid_t *in, *out; } CPUIDHelper;
typedef struct { readmem_t *in, *out; } ReadMemHelper;
static inline void cpuid(uint32_t op1, uint32_t op2, uint32_t *data);
};
extern "C" {
/* from sys/osfmk/i386/mp.c */
extern void mp_rendezvous(
void (*setup_func)(void *),
void (*action_func)(void *),
void (*teardown_func)(void *),
void *arg);
extern int cpu_number(void);
}
#define INVALID_MSR_LO 0x63744857
#define INVALID_MSR_HI 0x44697265