Enabling X2APIC
[akaros.git] / kern / arch / x86 / ros / mmu64.h
index ad6997b..3ebd79e 100644 (file)
@@ -1,5 +1,4 @@
-#ifndef ROS_INC_ARCH_MMU64_H
-#define ROS_INC_ARCH_MMU64_H
+#pragma once
 
 #ifndef ROS_INC_ARCH_MMU_H
 #error "Do not include include ros/arch/mmu64.h directly"
@@ -7,8 +6,15 @@
 
 #ifndef __ASSEMBLER__
 #include <ros/common.h>
-typedef unsigned long pte_t;
-typedef unsigned long pde_t;
+typedef unsigned long kpte_t;
+typedef unsigned long epte_t;
+
+typedef kpte_t* pte_t;
+
+typedef struct x86_pgdir {
+       kpte_t  *kpte;
+       uint64_t eptp;
+} pgdir_t;
 #endif
 
 /* Virtual memory map:                                  Virt Addresses
@@ -25,14 +31,14 @@ typedef unsigned long pde_t;
  *                     |                              |                     |
  * KERN_LOAD_ADDR -->  +------------------------------+ 0xffffffffc0000000 -+
  *                     |                              |
- *                     |          Local APIC          | RW/--  PGSIZE
+ *                     |            IOAPIC            | RW/--  APIC_SIZE (1MB)
  *                     |                              |
- *    LAPIC_BASE  -->  +------------------------------+ 0xffffffffbffff000
+ *   IOAPIC_BASE  -->  +------------------------------+ 0xffffffffbff00000
  *                     |                              |
- *                     |            IOAPIC            | RW/--  PGSIZE
+ *                     |                              | RW/--  APIC_SIZE (1MB)
  *                     |                              |
- *  IOAPIC_BASE,  -->  +------------------------------+ 0xffffffffbfffe000
- *  KERN_DYN_TOP       |   Kernel Dynamic Mappings    |
+ *   KERN_DYN_TOP -->  +------------------------------+ 0xffffffffbfe00000
+ *                     |   Kernel Dynamic Mappings    |
  *                     |              .               |
  *                     :              .               :
  *                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ RW/--
@@ -111,6 +117,17 @@ typedef unsigned long pde_t;
  *                     |     Program Data & Heap      |
  *                     |                              |
  *                     +------------------------------+ 0x0000000000400000
+ *                     .                              .
+ *                     .                              .
+ *                     |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
+ *                     |                              |
+ *                     |       ld.so (Dynamic)        |
+ *                     |                              |
+ * MMAP_LD_FIXED_VA    +------------------------------+ 0x0000000000100000
+ *                     |                              |
+ *                     |                              |
+ *                     |                              |
+ * MMAP_LOWEST_VA      +------------------------------+ 0x0000000000001000
  *                     |                              |
  *                     |       Empty Memory (*)       |
  *                     |                              |
@@ -134,8 +151,8 @@ typedef unsigned long pde_t;
  * the top 1 GB. */
 #define KERN_LOAD_ADDR  0xffffffffc0000000
 /* Static kernel mappings */
-#define LAPIC_BASE             (KERN_LOAD_ADDR - PGSIZE)
-#define IOAPIC_BASE            (LAPIC_BASE - PGSIZE)
+#define APIC_SIZE              0x100000
+#define IOAPIC_BASE            (KERN_LOAD_ADDR - APIC_SIZE)
 /* All arches must define this, which is the lower limit of their static
  * mappings, and where the dynamic mappings will start. */
 #define KERN_DYN_TOP   IOAPIC_BASE
@@ -231,32 +248,11 @@ typedef unsigned long pde_t;
 #define LA2PPN(la)             ((uintptr_t)(la) >> PGSHIFT)
 #define PTE2PPN(pte)   LA2PPN(pte)
 #define PGOFF(la)              ((uintptr_t)(la) & (PGSIZE - 1))
+#define NPTENTRIES             512
 
-/* construct PTE from PPN and flags */
-#define PTE(ppn, flags) ((ppn) << PGSHIFT | PGOFF(flags))
-
-/* construct linear address from indexes and offset */
-#define PGADDR(p4, p3, p2, p1, o) ((void*)(((p4) << PML4_SHIFT) |              \
-                                           ((p3) << PML3_SHIFT) |              \
-                                           ((p2) << PML2_SHIFT) |              \
-                                           ((p1) << PML1_SHIFT) |(o)))
-
-/* These are used in older code, referring to the outer-most page table */
-#define PDX(la)                        PML4(la)
-#define NPDENTRIES             512
 /* This is used in places (procinfo) meaning "size of smallest jumbo page" */
 #define PTSIZE PML2_PTE_REACH
 
-
-/* TODO: not sure if we'll need these - limited to 64bit code */
-/* this only gives us the L1 PML */
-#define PTX(la)                ((((uintptr_t) (la)) >> 12) & 0x1ff)
-#define JPGOFF(la)     (((uintptr_t) (la)) & 0x001FFFFF)
-#define NPTENTRIES             512
-#define JPGSIZE PTSIZE
-#define MAX_JUMBO_SHIFT PML3_SHIFT
-
-
 /* Page table/directory entry flags. */
 
 /* Some things to be careful of:  Global and PAT only apply to the last PTE in
@@ -275,14 +271,16 @@ typedef unsigned long pde_t;
 #define PTE_PAT                        0x080   /* Page attribute table */
 #define PTE_G                  0x100   /* Global Page */
 #define PTE_JPAT               0x800   /* Jumbo PAT */
+#define PTE_NOCACHE            (PTE_PWT | PTE_PCD)
 
 /* Permissions fields and common access modes.  These should be read as 'just
  * kernel or user too' and 'RO or RW'.  USER_RO means read-only for everyone. */
-#define PTE_PERM               (PTE_W | PTE_U)
-#define PTE_KERN_RW            PTE_W           // Kernel Read/Write
-#define PTE_KERN_RO            0               // Kernel Read-Only
-#define PTE_USER_RW            (PTE_W | PTE_U) // Kernel/User Read/Write
-#define PTE_USER_RO            PTE_U           // Kernel/User Read-Only
+#define PTE_PERM               (PTE_W | PTE_U | PTE_P)
+#define PTE_KERN_RW            (PTE_W | PTE_P)
+#define PTE_KERN_RO            PTE_P
+#define PTE_USER_RW            (PTE_W | PTE_U | PTE_P)
+#define PTE_USER_RO            (PTE_U | PTE_P)
+#define PTE_NONE               0
 
 /* The PTE/translation part of a PTE/virtual(linear) address.  It's used
  * frequently to be the page address of a virtual address.  Note this doesn't
@@ -295,7 +293,7 @@ typedef unsigned long pde_t;
 /* we must guarantee that for any PTE, exactly one of the following is true */
 #define PAGE_PRESENT(pte) ((pte) & PTE_P)
 #define PAGE_UNMAPPED(pte) ((pte) == 0)
-#define PAGE_PAGED_OUT(pte) (!PAGE_PRESENT(pte) && !PAGE_UNMAPPED(pte))
+#define PAGE_PAGED_OUT(pte) (0)        /* Need to use an OS reserved PTE bit */
 
 
 /* **************************************** */
@@ -510,5 +508,3 @@ typedef struct Pseudodesc {
 
 /* TLS 'syscall', coupled to trapentry64.S.  Needed a non-canon 'addr' */
 #define FASTCALL_SETFSBASE 0xf0f0000000000001
-
-#endif /* ROS_INC_ARCH_MMU64_H */