nckernel  0.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
x86.h
Go to the documentation of this file.
1 
10 struct x86_arch_data {
11  void *pma_pgd;
12  void *rpgd;
13 };
14 
15 struct x86_user_data {
17 };
18 
22 static inline void load_cr3(void *pgd_base)
23 {
24  struct cr3 cr3;
25 
26  cr3.pwt = 0;
27  cr3.pcd = 0;
28  cr3.pdb = (unsigned long)pgd_base / sysconf(_SC_PAGESIZE);
29 
30  asm volatile ("mov %0, %%cr3"::"r"(cr3));
31 }
32 
36 static inline void reload_cr3(void)
37 {
38  struct cr3 cr3;
39  asm volatile (
40  "mov %%cr3, %0\n"
41  "mov %1, %%cr3\n"
42  : "=r"(cr3)
43  : "r"(cr3)
44  );
45 }
46 
50 static inline void *read_cr3(void)
51 {
52  struct cr3 cr3;
53  unsigned long addr;
54 
55  asm volatile ("mov %%cr3, %0":"=r"(cr3):);
56  addr = cr3.pdb;
57  addr *= sysconf(_SC_PAGESIZE);
58 
59  return (void*)addr;
60 }
61