mmap() and friends using vm regions
[akaros.git] / kern / include / ros / memlayout.h
index 8e4e6e9..7bce867 100644 (file)
@@ -2,10 +2,11 @@
 #define ROS_INC_MEMLAYOUT_H
 
 #ifndef __ASSEMBLER__
-#include <arch/types.h>
-#include <arch/mmu.h>
+#include <ros/common.h>
 #endif /* not __ASSEMBLER__ */
 
+#include <ros/arch/mmu.h>
+
 /*
  * This file contains definitions for memory management in our OS,
  * which are relevant to both the kernel and user-mode software.
  *                     |         Kernel Stack         | RW/--  KSTKSIZE   |
  *                     | - - - - - - - - - - - - - - -|                 PTSIZE
  *                     |      Invalid Memory (*)      | --/--             |
- *    ULIM      ----> +------------------------------+ 0xbf800000      --+
+ *    ULIM      ---->  +------------------------------+ 0xbf800000      --+
  *                     |  Cur. Page Table (User R-)   | R-/R-  PTSIZE
- *    UVPT      ---->  +------------------------------+ 0xbf400000
- *                     |          RO PAGES            | R-/R-  PTSIZE
- *    UPAGES    ---->  +------------------------------+ 0xbf000000      --+
- *                     |  Unmapped (future expansion) | --/--             |
- *                     +------------------------------+ 0xbec01000      PTSIZE
- *                     |     Per-Process R/O Info     | R-/R-  PGSIZE     |
- * UTOP, UINFO  ---->  +------------------------------+ 0xbec00000      --+
- *                     |     Async Syscall Ring       | RW/RW  PGSIZE     |
- *   USYSCALL   ---->  +------------------------------+ 0xbebff000        |
- *                     |     Async Sysevent Ring      | RW/RW  PGSIZE     |
- *   USYSEVENT  ---->  +------------------------------+ 0xbebfe000      PTSIZE
- *                     |      Global Shared Page      | RW/RW  PGSIZE     |
- *     UGDATA   ---->  +------------------------------+ 0xbebfd000        |
- *                     |  Unmapped (future expansion) | --/--             |
- *   UXSTACKTOP ---->  +------------------------------+ 0xbe800000      --+
+ *    UVPT      ---->  +------------------------------+ 0xbf400000      --+
+ *                     | Unmapped (expandable region) |                   |
+ *                     |                              | R-/R-            PTSIZE
+ *                     |     Per-Process R/O Info     |                   |
+ * UTOP, UINFO  ---->  +------------------------------+ 0xbf000000      --+
+ *                     | Unmapped (expandable region) |                   |
+ *                     |                              | RW/RW            PTSIZE
+ *                     |     Per-Process R/W Data     |                   |
+ *    UDATA     ---->  +------------------------------+ 0xbec00000      --+
+ *                     |    Global Shared R/W Data    | RW/RW  PGSIZE
+ * UXSTACKTOP,UGDATA ->+------------------------------+ 0xbebff000
  *                     |     User Exception Stack     | RW/RW  PGSIZE
- *                     +------------------------------+ 0xbe7ff000
+ *                     +------------------------------+ 0xbebfe000
+ *                     |       Empty Memory (*)       | --/--  PGSIZE
+ *    USTACKTOP  --->  +------------------------------+ 0xbebfd000
+ *                     |      Normal User Stack       | RW/RW  256*PGSIZE (1MB)
+ *                     +------------------------------+ 0xbeafd000
  *                     |       Empty Memory (*)       | --/--  PGSIZE
- *    USTACKTOP  --->  +------------------------------+ 0xbe7fe000
- *                     |      Normal User Stack       | RW/RW  PGSIZE
- *                     +------------------------------+ 0xbe7fd000
+ *    USTACKBOT  --->  +------------------------------+ 0xbeafc000
  *                     |                              |
  *                     |                              |
  *                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -80,9 +79,6 @@
  */
 
 
-// All physical memory mapped at this address
-#define        KERNBASE        0xC0000000
-
 // At IOPHYSMEM (640K) there is a 384K hole for I/O.  From the kernel,
 // IOPHYSMEM can be addressed at KERNBASE + IOPHYSMEM.  The hole ends
 // at physical address EXTPHYSMEM.
 
 // Same as VPT but read-only for users
 #define UVPT           (ULIM - PTSIZE)
-// Read-only copies of the Page structures
-#define UPAGES         (UVPT - PTSIZE)
-// Read-only, per-process shared info structures
-#define UINFO          (UPAGES - PTSIZE)
-#define UINFO_PAGES 1
 
 /*
  * Top of user VM. User can manipulate VA from UTOP-1 and down!
  */
 
 // Top of user-accessible VM
-#define UTOP           UINFO
+#define UTOP           (UVPT - PTSIZE)
+// Read-only, per-process shared info structures
+#define UINFO          UTOP
 
 // Read-write, per-process shared page for sending asynchronous 
 // syscalls to the kernel
-#define USYSCALL    (UTOP - PGSIZE)
-
-// Read-write, per-process shared page for receiving asynchronous 
-// sysevents from the kernel
-#define USYSEVENT   (USYSCALL - PGSIZE)
+#define UDATA    (UTOP - PTSIZE)
 
 // Read-write, global page.  Shared by all processes.  Can't be trusted.
-#define UGDATA   (USYSEVENT - PGSIZE)
+#define UGDATA   (UDATA - PGSIZE)
 
 // Top of one-page user exception stack
-#define UXSTACKTOP     (UTOP - PTSIZE)
+#define UXSTACKTOP     UGDATA
+/* Limit of what is mmap()/munmap()-able */
+#define UMAPTOP UXSTACKTOP
 // Next page left invalid to guard against exception stack overflow; then:
 // Top of normal user stack
 #define USTACKTOP      (UXSTACKTOP - 2*PGSIZE)
+// Maximum stack depth preallocated to 1MB
+#define USTACK_NUM_PAGES       256
+// Next page left invalid to guard against stack overflow
+// Maximum bottom of normal user stack
+#define USTACKBOT      (USTACKTOP - (USTACK_NUM_PAGES+1)*PGSIZE)
+
+// Arbitrary boundary between the break and the start of
+// memory returned by calls to mmap with addr = 0
+#define BRK_END 0x20000000
 
 // Where user programs generally begin
 #define UTEXT          (2*PTSIZE)
  * will always be available at virtual address (VPT + (VPT >> PGSHIFT)), to
  * which vpd is set in entry.S.
  */
-typedef uint32_t pte_t;
-typedef uint32_t pde_t;
 
-extern volatile pte_t vpt[];     // VA of "virtual page table"
-extern volatile pde_t vpd[];     // VA of current page directory
+#ifdef __IVY__
+#pragma cilnoremove("vpt_lock", "vpd_lock")
+#endif
+extern volatile uint32_t vpt_lock;
+extern volatile uint32_t vpd_lock;
+
+extern volatile pte_t SLOCKED(&vpt_lock) (COUNT(PTSIZE) SREADONLY vpt)[]; // VA of "virtual page table"
+extern volatile pde_t SLOCKED(&vpd_lock) (COUNT(PTSIZE) SREADONLY vpd)[]; // VA of current page directory
 
 #endif /* !__ASSEMBLER__ */
 #endif /* !ROS_INC_MEMLAYOUT_H */