Guest User

Untitled

a guest
Apr 15th, 2025
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.77 KB | Source Code | 0 0
  1. #include <stdint.h>
  2.  
  3. typedef struct page_map_level_4
  4. {
  5.     page_map_level_4_entry_t *map;
  6. } page_map_level_4_t;
  7.  
  8. typedef struct page_map_level_4_entry {
  9.     /// @brief Is this a valid entry?
  10.     uint64_t present:1;
  11.     /// @brief If clear, this page is read only;
  12.     uint64_t writable:1;
  13.     /// @brief If set, this page is user accessable;
  14.     uint64_t user:1;
  15.     /// @brief If set, write through caching is enabled
  16.     uint64_t write_through:1;
  17.     /// @brief Page will not be cached
  18.     uint64_t cache_disable:1;
  19.     /// @brief If set, this page has been recently accessed by the CPU
  20.     uint64_t accessed:1;
  21.     uint64_t unused_0:1;
  22.     uint64_t reserved_0:1;
  23.     uint64_t unused_1:4;
  24.     /// @brief The address of the page directory pointer table
  25.     uint64_t address:36;
  26.     uint64_t reserved_1:4;
  27.     uint64_t unused_2:11;
  28.     uint64_t disable_execution:1;
  29. } __attribute__((packed)) page_map_level_4_entry_t;
  30.  
  31. typedef struct page_directory_pointer_table
  32. {
  33.     page_directory_pointer_table_entry_t *map;
  34. } page_directory_pointer_table_t;
  35.  
  36. typedef struct page_directory_pointer_table_entry {
  37.     /// @brief Is this a valid entry?
  38.     uint64_t present:1;
  39.     /// @brief If clear, this page is read only;
  40.     uint64_t writable:1;
  41.     /// @brief If set, this page is user accessable;
  42.     uint64_t user:1;
  43.     /// @brief If set, write through caching is enabled
  44.     uint64_t write_through:1;
  45.     /// @brief Page will not be cached
  46.     uint64_t cache_disable:1;
  47.     /// @brief If set, this page has been recently accessed by the CPU
  48.     uint64_t accessed:1;
  49.     uint64_t unused_0:1;
  50.     /// @brief Set to 0
  51.     uint64_t page_size:1;
  52.     uint64_t unused_1:4;
  53.     /// @brief The address of the page directory pointer table
  54.     uint64_t address:36;
  55.     uint64_t reserved_1:4;
  56.     uint64_t unused_2:11;
  57.     uint64_t disable_execution:1;
  58. } __attribute__((packed)) page_directory_pointer_table_entry_t;
  59.  
  60. typedef struct page_directory
  61. {
  62.     page_directory_entry_t *map;
  63. } page_directory_t;
  64.  
  65. typedef struct page_directory_entry {
  66.     /// @brief Is this a valid entry?
  67.     uint64_t present:1;
  68.     /// @brief If clear, this page is read only;
  69.     uint64_t writable:1;
  70.     /// @brief If set, this page is user accessable;
  71.     uint64_t user:1;
  72.     /// @brief If set, write through caching is enabled
  73.     uint64_t write_through:1;
  74.     /// @brief Page will not be cached
  75.     uint64_t cache_disable:1;
  76.     /// @brief If set, this page has been recently accessed by the CPU
  77.     uint64_t accessed:1;
  78.     uint64_t unused_0:1;
  79.     /// @brief Set to 0
  80.     uint64_t page_size:1;
  81.     uint64_t unused_1:4;
  82.     /// @brief The address of the page directory pointer table
  83.     uint64_t address:36;
  84.     uint64_t reserved_1:4;
  85.     uint64_t unused_2:11;
  86.     uint64_t disable_execution:1;
  87. } __attribute__((packed)) page_directory_entry_t;
  88.  
  89. typedef struct page_table
  90. {
  91.     page_directory_entry_t *map;
  92. } page_table_t;
  93.  
  94. typedef struct page_table_entry
  95. {
  96.     /// @brief Is this a valid entry?
  97.     uint64_t present:1;
  98.     /// @brief If clear, this page is read only;
  99.     uint64_t writable:1;
  100.     /// @brief If set, this page is user accessable;
  101.     uint64_t user:1;
  102.     /// @brief If set, write through caching is enabled
  103.     uint64_t write_through:1;
  104.     /// @brief Page will not be cached
  105.     uint64_t cache_disable:1;
  106.     /// @brief If set, this page has been recently accessed by the CPU
  107.     uint64_t avalible:3;
  108.     /// @brief The page has been written to
  109.     uint64_t ditry:1;
  110.     /// @brief Use Page Attribute Table
  111.     uint64_t pat:1;
  112.     uint64_t global:1;
  113.     uint64_t unused_0:3;
  114.     uint64_t address:36;
  115.     uint64_t reserved:2;
  116.     uint64_t unused_1:7;
  117.     uint64_t protection_key:4;
  118.     uint64_t execution_disable:1;
  119. } __attribute__((packed)) page_table_entry_t;
Advertisement
Add Comment
Please, Sign In to add comment