luajitos

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

paging.h (1592B)


      1 #ifndef PAGING_H
      2 #define PAGING_H
      3 
      4 #include <stdint.h>
      5 
      6 /* Page directory and table flags */
      7 #define PAGE_PRESENT    0x001  /* Page is present in memory */
      8 #define PAGE_WRITE      0x002  /* Page is writable */
      9 #define PAGE_USER       0x004  /* Page is accessible from user mode */
     10 #define PAGE_WRITETHROUGH 0x008  /* Write-through caching */
     11 #define PAGE_NOCACHE    0x010  /* Disable caching */
     12 #define PAGE_ACCESSED   0x020  /* Set by CPU when page is accessed */
     13 #define PAGE_DIRTY      0x040  /* Set by CPU when page is written to */
     14 #define PAGE_SIZE       0x080  /* 4MB pages (if set in page directory) */
     15 #define PAGE_GLOBAL     0x100  /* Page won't be flushed from TLB */
     16 
     17 /* Page table entry */
     18 typedef uint32_t page_table_entry_t;
     19 
     20 /* Page directory entry */
     21 typedef uint32_t page_directory_entry_t;
     22 
     23 /* Page table (1024 entries, each covering 4KB) */
     24 typedef struct {
     25     page_table_entry_t entries[1024];
     26 } __attribute__((aligned(4096))) page_table_t;
     27 
     28 /* Page directory (1024 entries, each pointing to a page table) */
     29 typedef struct {
     30     page_directory_entry_t entries[1024];
     31 } __attribute__((aligned(4096))) page_directory_t;
     32 
     33 /* Initialize paging with identity mapping */
     34 void paging_init(void);
     35 
     36 /* Map a virtual address to a physical address with given flags */
     37 void paging_map_page(uint32_t virtual_addr, uint32_t physical_addr, uint32_t flags);
     38 
     39 /* Allocate and map memory for JIT-compiled code (executable) */
     40 void* paging_alloc_executable(uint32_t size);
     41 
     42 /* Get the physical address for a virtual address */
     43 uint32_t paging_get_physical(uint32_t virtual_addr);
     44 
     45 #endif