Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include "console.h"
  2.  
  3. static inline void lcr3(unsigned int val)
  4. {
  5. asm volatile("movl %0,%%cr3" : : "r" (val));
  6. }
  7.  
  8. static inline void halt(void)
  9. {
  10. asm volatile("hlt" : : );
  11. }
  12.  
  13. int main(void)
  14. {
  15. int i;
  16. int sum = 0;
  17.  
  18. // Initialize the console
  19. uartinit();
  20.  
  21. printk("Hello from C\n");
  22.  
  23. unsigned int ptd_table[1024] __attribute__((aligned(4096)));
  24. unsigned int pt_table1[1024] __attribute__((aligned(4096)));
  25. unsigned int pt_table2[1024] __attribute__((aligned(4096)));
  26. ptd_table[0] = (unsigned int)pt_table1 | 3;
  27. ptd_table[1] = (unsigned int)pt_table2 | 3;
  28.  
  29.  
  30.  
  31. for (i = 0; i < 1024; i++) {
  32. pt_table1[i] = (i * 4096) | 3;
  33. }
  34.  
  35. for (i = 0; i < 1024; i++) {
  36. pt_table2[i] = ((1024 * 4096) + (i * 4096)) | 3;
  37. }
  38.  
  39.  
  40. // Create your page table here
  41.  
  42. lcr3((unsigned int)ptd_table);
  43.  
  44. for (i = 0; i < 64; i++) {
  45. int *p = (int *)(i * 4096 * 32);
  46. sum += *p;
  47.  
  48. printk("page\n");
  49. }
  50. halt();
  51. return sum;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement