refactor: add a async read/write variant to device ops, with allow async io to be...
[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 static inline ptr_t
21 cpu_get_fp()
22 {
23     ptr_t val;
24     asm("movl %%ebp, %0" : "=r"(val)::);
25     return val;
26 }
27
28 /**
29  * @brief Load current processor state
30  *
31  * @return u32_t
32  */
33 static inline u32_t
34 cpu_ldstate()
35 {
36     ptr_t val;
37     asm volatile("pushf\n"
38                  "popl %0\n"
39                  : "=r"(val)::);
40     return val;
41 }
42
43 /**
44  * @brief Load current processor config
45  *
46  * @return u32_t
47  */
48 static inline u32_t
49 cpu_ldconfig()
50 {
51     ptr_t val;
52     asm volatile("movl %%cr0,%0" : "=r"(val));
53     return val;
54 }
55
56 /**
57  * @brief Change current processor state
58  *
59  * @return u32_t
60  */
61 static inline void
62 cpu_chconfig(u32_t val)
63 {
64     asm("mov %0, %%cr0" ::"r"(val));
65 }
66
67 /**
68  * @brief Load current virtual memory space
69  *
70  * @return u32_t
71  */
72 static inline u32_t
73 cpu_ldvmspace()
74 {
75     ptr_t val;
76     asm volatile("movl %%cr3,%0" : "=r"(val));
77     return val;
78 }
79
80 /**
81  * @brief Change current virtual memory space
82  *
83  * @return u32_t
84  */
85 static inline void
86 cpu_chvmspace(u32_t val)
87 {
88     asm("mov %0, %%cr3" ::"r"(val));
89 }
90
91 /**
92  * @brief Flush a certain TLB record
93  *
94  * @return u32_t
95  */
96 static inline void
97 cpu_flush_page(ptr_t va)
98 {
99     asm volatile("invlpg (%0)" ::"r"(va) : "memory");
100 }
101
102 /**
103  * @brief Flush entire TLB
104  *
105  */
106 static inline void
107 cpu_flush_vmspace()
108 {
109     asm("movl %%cr3, %%eax\n"
110         "movl %%eax, %%cr3" ::
111           : "eax");
112 }
113
114 static inline void
115 cpu_enable_interrupt()
116 {
117     asm volatile("sti");
118 }
119
120 static inline void
121 cpu_disable_interrupt()
122 {
123     asm volatile("cli");
124 }
125
126 static inline void
127 cpu_wait()
128 {
129     asm("hlt");
130 }
131
132 /**
133  * @brief Read exeception address
134  *
135  * @return ptr_t
136  */
137 static inline ptr_t
138 cpu_ldeaddr()
139 {
140     ptr_t val;
141     asm volatile("movl %%cr2,%0" : "=r"(val));
142     return val;
143 }
144
145 #endif /* __LUNAIX_CPU_H */