-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpu_data.h
More file actions
66 lines (53 loc) · 1.37 KB
/
Copy pathcpu_data.h
File metadata and controls
66 lines (53 loc) · 1.37 KB
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
/* SPDX-License-Identifier: MIT */
#pragma once
#include <stdint.h>
#include <processor.h>
#include <compiler.h>
#include <x86.h>
/**
* CPU-specific data. Each CPU in SMP holds this struct.
* Use the get_current_cpu_data() function to get this struct
* for the current CPU.
*/
typedef struct cpu_data {
uint32_t cpu_number;
thread_t cpu_current_thread;
processor_t *cpu_processor;
uint8_t cpu_lapic_id;
uint8_t cpu_lapic_version;
bool cpu_running;
} cpu_data_t;
extern cpu_data_t *cpu_data_ptr[];
/**
* Initialize the cpu data for boot processor.
*/
void boot_cpu_init(void);
/**
* Called once by the boot processor after VM and heap is online to
* initialize the cpu data for secondary processors.
*/
void secondary_cpus_init(void);
/**
* Get the cpu data object.
*
* @param cpu CPU number.
*
* @return CPU data for the specified CPU number.
*/
static inline cpu_data_t *get_cpu_data(uint32_t cpu)
{
return cpu_data_ptr[cpu];
}
static inline cpu_data_t *get_current_cpu_data(void)
{
return (cpu_data_t *)x86_get_gs_offset(__offsetof(cpu_data_t, cpu_number));
}
static inline thread_t *get_current_thread()
{
return (thread_t *)x86_get_gs_offset(
__offsetof(cpu_data_t, cpu_current_thread));
}
static inline uint32_t get_current_cpu_number(void)
{
return (uint32_t)x86_get_gs_offset(__offsetof(cpu_data_t, cpu_number));
}