fix: (blkio) enforce disk io buffer size alignment (to block size)
[lunaix-os.git] / lunaix-os / includes / hal / cpu.h
index 1a3173bb2771079c9c564aa9392b1aa75eb3d6aa..5789d4a41430f955d8c939f4e79d168d445a26cd 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <stdint.h>
 
 
 #include <stdint.h>
 
+#define SEL_RPL(selector) ((selector)&0x3)
+
 typedef unsigned int reg32;
 typedef unsigned short reg16;
 
 typedef unsigned int reg32;
 typedef unsigned short reg16;
 
@@ -20,35 +22,52 @@ typedef struct
 
 typedef struct
 {
 
 typedef struct
 {
-    reg16 ss;
-    reg16 es;
     reg16 ds;
     reg16 ds;
+    reg16 es;
     reg16 fs;
     reg16 gs;
     reg16 fs;
     reg16 gs;
-    reg16 cs;
 } __attribute__((packed)) sg_reg;
 
 void
 cpu_get_brand(char* brand_out);
 
 } __attribute__((packed)) sg_reg;
 
 void
 cpu_get_brand(char* brand_out);
 
+int
+cpu_has_apic();
+
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wreturn-type"
 static inline reg32
 cpu_rcr0()
 {
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wreturn-type"
 static inline reg32
 cpu_rcr0()
 {
-    asm("mov %cr0, %eax");
+    uintptr_t val;
+    asm volatile("movl %%cr0,%0" : "=r"(val));
+    return val;
 }
 
 static inline reg32
 cpu_rcr2()
 {
 }
 
 static inline reg32
 cpu_rcr2()
 {
-    asm("mov %cr2, %eax");
+    uintptr_t val;
+    asm volatile("movl %%cr2,%0" : "=r"(val));
+    return val;
 }
 
 static inline reg32
 cpu_rcr3()
 {
 }
 
 static inline reg32
 cpu_rcr3()
 {
-    asm("mov %cr3, %eax");
+    uintptr_t val;
+    asm volatile("movl %%cr3,%0" : "=r"(val));
+    return val;
+}
+
+static inline reg32
+cpu_reflags()
+{
+    uintptr_t val;
+    asm volatile("pushf\n"
+                 "popl %0\n"
+                 : "=r"(val)::);
+    return val;
 }
 #pragma GCC diagnostic pop
 
 }
 #pragma GCC diagnostic pop
 
@@ -73,19 +92,19 @@ cpu_lcr3(reg32 v)
 static inline void
 cpu_invplg(void* va)
 {
 static inline void
 cpu_invplg(void* va)
 {
-    asm("invlpg (%0)" ::"r"((uintptr_t)va) : "memory");
+    asm volatile("invlpg (%0)" ::"r"((uintptr_t)va) : "memory");
 }
 
 static inline void
 cpu_enable_interrupt()
 {
 }
 
 static inline void
 cpu_enable_interrupt()
 {
-    asm("sti");
+    asm volatile("sti");
 }
 
 static inline void
 cpu_disable_interrupt()
 {
 }
 
 static inline void
 cpu_disable_interrupt()
 {
-    asm("cli");
+    asm volatile("cli");
 }
 
 static inline void
 }
 
 static inline void
@@ -98,4 +117,16 @@ cpu_invtlb()
         : "r"(interm));
 }
 
         : "r"(interm));
 }
 
+static inline void
+cpu_int(int vect)
+{
+    asm("int %0" ::"i"(vect));
+}
+
+void
+cpu_rdmsr(uint32_t msr_idx, uint32_t* reg_high, uint32_t* reg_low);
+
+void
+cpu_wrmsr(uint32_t msr_idx, uint32_t reg_high, uint32_t reg_low);
+
 #endif
\ No newline at end of file
 #endif
\ No newline at end of file