1/*
2 * Copyright (C) 2020-2022 The opuntiaOS Project Authors.
3 * + Contributed by Nikita Melekhin <nimelehin@gmail.com>
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#ifndef _KERNEL_TASKING_CPU_H
10#define _KERNEL_TASKING_CPU_H
11
12#include <drivers/generic/fpu.h>
13#include <platform/generic/cpu.h>
14#include <tasking/bits/sched.h>
15#include <tasking/proc.h>
16#include <tasking/thread.h>
17
18#define RUNNING_THREAD (THIS_CPU->running_thread)
19
20static inline void cpu_enter_kernel_space()
21{
22 THIS_CPU->current_state = CPU_IN_KERNEL;
23}
24
25static inline void cpu_leave_kernel_space()
26{
27 THIS_CPU->current_state = CPU_IN_USERLAND;
28}
29
30static inline void cpu_tick()
31{
32 if (THIS_CPU->running_thread->process->is_kthread) {
33 THIS_CPU->stat_system_and_idle_ticks++;
34 } else {
35 THIS_CPU->stat_user_ticks++;
36 }
37}
38
39#endif // _KERNEL_TASKING_CPU_H