Decoupling Architectural-specific Code (#35)
[lunaix-os.git] / lunaix-os / arch / i386 / includes / sys / cpu.h
1 #ifndef __LUNAIX_CPU_H
2 #define __LUNAIX_CPU_H
3
4 #include <lunaix/types.h>
5
6 /**
7  * @brief Get processor ID string
8  *
9  * @param id_out
10  */
11 void
12 cpu_get_id(char* id_out);
13
14 void
15 cpu_trap_sched();
16
17 void
18 cpu_trap_panic(char* message);
19
20
21 /**
22  * @brief Load current processor state
23  *
24  * @return reg_t
25  */
26 static inline reg_t
27 cpu_ldstate()
28 {
29     ptr_t val;
30     asm volatile("pushf\n"
31                  "popl %0\n"
32                  : "=r"(val)::);
33     return val;
34 }
35
36 /**
37  * @brief Load current processor config
38  *
39  * @return reg_t
40  */
41 static inline reg_t
42 cpu_ldconfig()
43 {
44     reg_t val;
45     asm volatile("movl %%cr0,%0" : "=r"(val));
46     return val;
47 }
48
49 /**
50  * @brief Change current processor state
51  *
52  * @return reg_t
53  */
54 static inline void
55 cpu_chconfig(reg_t val)
56 {
57     asm("mov %0, %%cr0" ::"r"(val));
58 }
59
60 /**
61  * @brief Change current virtual memory space
62  *
63  * @return reg_t
64  */
65 static inline void
66 cpu_chvmspace(reg_t val)
67 {
68     asm("mov %0, %%cr3" ::"r"(val));
69 }
70
71 static inline void
72 cpu_enable_interrupt()
73 {
74     asm volatile("sti");
75 }
76
77 static inline void
78 cpu_disable_interrupt()
79 {
80     asm volatile("cli");
81 }
82
83 static inline void
84 cpu_wait()
85 {
86     asm("hlt");
87 }
88
89 /**
90  * @brief Read exeception address
91  *
92  * @return ptr_t
93  */
94 static inline ptr_t
95 cpu_ldeaddr()
96 {
97     ptr_t val;
98     asm volatile("movl %%cr2,%0" : "=r"(val));
99     return val;
100 }
101
102 #endif /* __LUNAIX_CPU_H */