basic process support and some syscalls
[lunaix-os.git] / lunaix-os / includes / lunaix / mm / page.h
index e97de1d80b41cab1660ee0e2b886666fb195d5c5..a6b3162a9541379b1b35509f11015c6713be4a3b 100644 (file)
@@ -1,15 +1,18 @@
 #ifndef __LUNAIX_PAGE_H
 #define __LUNAIX_PAGE_H
 #include <stdint.h>
-#include <lunaix/constants.h>
+#include <lunaix/common.h>
 
-#define PG_SIZE_BITS              12
+#define PG_SIZE_BITS                12
+#define PG_SIZE                     (1 << PG_SIZE_BITS)
 #define PG_INDEX_BITS               10
 
 #define PG_MAX_ENTRIES              1024U
 #define PG_LAST_TABLE               PG_MAX_ENTRIES - 1
 #define PG_FIRST_TABLE              0
 
+#define PTE_NULL                    0
+
 #define P2V(paddr)          ((uintptr_t)(paddr)  +  HIGHER_HLF_BASE)
 #define V2P(vaddr)          ((uintptr_t)(vaddr)  -  HIGHER_HLF_BASE)
 
@@ -43,6 +46,9 @@
 #define PG_ENTRY_FLAGS(entry)   (entry & 0xFFFU)
 #define PG_ENTRY_ADDR(entry)   (entry & ~0xFFFU)
 
+#define HAS_FLAGS(entry, flags)             ((PG_ENTRY_FLAGS(entry) & (flags)) == flags)
+#define CONTAINS_FLAGS(entry, flags)        (PG_ENTRY_FLAGS(entry) & (flags))
+
 #define PG_PREM_R              PG_PRESENT
 #define PG_PREM_RW             PG_PRESENT | PG_WRITE
 #define PG_PREM_UR             PG_PRESENT | PG_ALLOW_USER
@@ -64,6 +70,7 @@
 typedef unsigned long ptd_t;
 typedef unsigned long pt_t;
 typedef unsigned int pt_attr;
+typedef uint32_t x86_pte_t;
 
 /**
  * @brief 虚拟映射属性
@@ -76,7 +83,23 @@ typedef struct {
     uintptr_t pa;
     // 映射的flags
     uint16_t flags;
+    // PTE地址
+    x86_pte_t *pte;
 } v_mapping;
 
+typedef struct
+{
+    x86_pte_t entry[PG_MAX_ENTRIES];
+} __attribute__((packed)) x86_page_table;
+
+
+extern void __pg_mount_point;
+
+/* 三个页挂载点: 用于临时创建&编辑页表 */
+
+#define PG_MOUNT_1  (&__pg_mount_point)
+#define PG_MOUNT_2  (&__pg_mount_point + 0x1000)
+#define PG_MOUNT_3  (&__pg_mount_point + 0x2000)
+
 
 #endif /* __LUNAIX_PAGE_H */