[Kernel] Implement GetSystemTick

This commit is contained in:
wheremyfoodat 2022-09-21 00:48:51 +03:00
parent 5bcdf4d063
commit cbefe3c2d0
4 changed files with 19 additions and 0 deletions

View file

@ -13,6 +13,7 @@ class CPU;
class MyEnvironment final : public Dynarmic::A32::UserCallbacks {
public:
u64 ticksLeft = 0;
u64 totalTicks = 0;
Memory& mem;
Kernel& kernel;
@ -80,6 +81,8 @@ public:
}
void AddTicks(u64 ticks) override {
totalTicks += ticks;
if (ticks > ticksLeft) {
ticksLeft = 0;
return;
@ -148,6 +151,10 @@ public:
cp15->setTLSBase(value);
}
u64 getTicks() {
return env.totalTicks;
}
void runFrame() {
env.ticksLeft = 268111856 / 60;
const auto exitReason = jit->Run();

View file

@ -92,6 +92,7 @@ class Kernel {
void getResourceLimit();
void getResourceLimitLimitValues();
void getResourceLimitCurrentValues();
void getSystemTick();
void sendSyncRequest();
void svcCloseHandle();
void connectToPort();

View file

@ -19,6 +19,7 @@ CPU::CPU(Memory& mem, Kernel& kernel) : mem(mem), env(mem, kernel, *this) {
void CPU::reset() {
setCPSR(CPSR::UserMode);
setFPSCR(FPSCR::ThreadDefault);
env.totalTicks = 0;
cp15->reset();
cp15->setTLSBase(VirtualAddrs::TLSBase); // Set cp15 TLS pointer to the main thread's thread-local storage

View file

@ -26,6 +26,7 @@ void Kernel::serviceSVC(u32 svc) {
case 0x22: arbitrateAddress(); break;
case 0x23: svcCloseHandle(); break;
case 0x24: waitSynchronization1(); break;
case 0x28: getSystemTick(); break;
case 0x2D: connectToPort(); break;
case 0x32: sendSyncRequest(); break;
case 0x38: getResourceLimit(); break;
@ -108,6 +109,15 @@ void Kernel::svcCloseHandle() {
regs[0] = SVCResult::Success;
}
// u64 GetSystemTick()
void Kernel::getSystemTick() {
printf("GetSystemTick()\n");
u64 ticks = cpu.getTicks();
regs[0] = u32(ticks);
regs[1] = u32(ticks >> 32);
}
// Result OutputDebugString(const char* str, s32 size)
// TODO: Does this actually write an error code in r0 and is the above signature correct?
void Kernel::outputDebugString() {