PerformanceCounter.

This commit is contained in:
Ben Vanik 2013-09-25 18:36:34 -07:00
parent b7fd4f975d
commit 03a68d4c49
3 changed files with 35 additions and 2 deletions

View File

@ -635,6 +635,7 @@ XEEMITTER(mfspr, 0x7C0002A6, XFX)(X64Emitter& e, X86Compiler& c, InstrDat
// CTR
v = e.ctr_value();
break;
// 268 + 269 = TB + TBU
default:
XEINSTRNOTIMPLEMENTED();
return 1;
@ -648,8 +649,16 @@ XEEMITTER(mfspr, 0x7C0002A6, XFX)(X64Emitter& e, X86Compiler& c, InstrDat
}
XEEMITTER(mftb, 0x7C0002E6, XFX)(X64Emitter& e, X86Compiler& c, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
LARGE_INTEGER counter;
if (QueryPerformanceCounter(&counter)) {
e.update_gpr_value(i.XFX.RT, e.get_uint64(counter.QuadPart));
} else {
e.update_gpr_value(i.XFX.RT, e.get_uint64(0));
}
e.clear_constant_gpr_value(i.XFX.RT);
return 0;
}
XEEMITTER(mtcrf, 0x7C000120, XFX)(X64Emitter& e, X86Compiler& c, InstrData& i) {

View File

@ -155,6 +155,26 @@ SHIM_CALL KeGetCurrentProcessType_shim(
}
uint64_t xeKeQueryPerformanceFrequency() {
LARGE_INTEGER frequency;
if (QueryPerformanceFrequency(&frequency)) {
return frequency.QuadPart;
} else {
return 0;
}
}
SHIM_CALL KeQueryPerformanceFrequency_shim(
xe_ppc_state_t* ppc_state, KernelState* state) {
XELOGD(
"KeQueryPerformanceFrequency()");
uint64_t result = xeKeQueryPerformanceFrequency();
SHIM_SET_RETURN(result);
}
// The TLS system used here is a bit hacky, but seems to work.
// Both Win32 and pthreads use unsigned longs as TLS indices, so we can map
// right into the system for these calls. We're just round tripping the IDs and
@ -414,6 +434,8 @@ void xe::kernel::xboxkrnl::RegisterThreadingExports(
SHIM_SET_MAPPING("xboxkrnl.exe", KeGetCurrentProcessType, state);
SHIM_SET_MAPPING("xboxkrnl.exe", KeQueryPerformanceFrequency, state);
SHIM_SET_MAPPING("xboxkrnl.exe", KeTlsAlloc, state);
SHIM_SET_MAPPING("xboxkrnl.exe", KeTlsFree, state);
SHIM_SET_MAPPING("xboxkrnl.exe", KeTlsGetValue, state);

View File

@ -28,6 +28,8 @@ X_STATUS xeExCreateThread(
uint32_t xeKeGetCurrentProcessType();
uint64_t xeKeQueryPerformanceFrequency();
uint32_t xeKeTlsAlloc();
int KeTlsFree(uint32_t tls_index);
uint32_t xeKeTlsGetValue(uint32_t tls_index);