summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/svc/svc_tick.cpp
blob: 5613364821df973864d4660b64dec2f548e6b1d8 (plain) (blame)
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
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "core/core.h"
#include "core/core_timing.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/svc.h"

namespace Kernel::Svc {

/// This returns the total CPU ticks elapsed since the CPU was powered-on
int64_t GetSystemTick(Core::System& system) {
    LOG_TRACE(Kernel_SVC, "called");

    auto& core_timing = system.CoreTiming();

    // Returns the value of cntpct_el0 (https://switchbrew.org/wiki/SVC#svcGetSystemTick)
    const u64 result{core_timing.GetClockTicks()};

    if (!system.Kernel().IsMulticore()) {
        core_timing.AddTicks(400U);
    }

    return static_cast<int64_t>(result);
}

int64_t GetSystemTick64(Core::System& system) {
    return GetSystemTick(system);
}

int64_t GetSystemTick64From32(Core::System& system) {
    return GetSystemTick(system);
}

} // namespace Kernel::Svc