1 #ifndef ROS_INC_MEMLAYOUT_H
2 #define ROS_INC_MEMLAYOUT_H
5 #include <ros/common.h>
6 #endif /* not __ASSEMBLER__ */
8 #include <ros/arch/mmu.h>
11 * This file contains definitions for memory management in our OS,
12 * which are relevant to both the kernel and user-mode software.
16 * Virtual memory map: Permissions
19 * 4 Gig --------> +------------------------------+
21 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 * |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| RW/--
27 * | Remapped Physical Memory | RW/--
29 * KERNBASE -----> +------------------------------+ 0xc0000000
30 * | Cur. Page Table (Kern. RW) | RW/-- PTSIZE
31 * VPT,KSTACKTOP--> +------------------------------+ 0xbfc00000 --+
32 * | Kernel Stack | RW/-- KSTKSIZE |
33 * | - - - - - - - - - - - - - - -| PTSIZE
34 * | Invalid Memory (*) | --/-- |
35 * ULIM ----> +------------------------------+ 0xbf800000 --+
36 * | Cur. Page Table (User R-) | R-/R- PTSIZE
37 * UVPT ----> +------------------------------+ 0xbf400000 --+
38 * | Unmapped (expandable region) | |
40 * | Per-Process R/O Info | |
41 * UTOP, UINFO ----> +------------------------------+ 0xbf000000 --+
42 * | Unmapped (expandable region) | |
44 * | Per-Process R/W Data | |
45 * UDATA ----> +------------------------------+ 0xbec00000 --+
46 * | Global Shared R/W Data | RW/RW PGSIZE
47 * UXSTACKTOP,UGDATA ->+------------------------------+ 0xbebff000
48 * | User Exception Stack | RW/RW PGSIZE
49 * +------------------------------+ 0xbebfe000
50 * | Empty Memory (*) | --/-- PGSIZE
51 * USTACKTOP ---> +------------------------------+ 0xbebfd000
52 * | Normal User Stack | RW/RW 256*PGSIZE (1MB)
53 * +------------------------------+ 0xbeafd000
54 * | Empty Memory (*) | --/-- PGSIZE
55 * USTACKBOT ---> +------------------------------+ 0xbeafc000
58 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62 * |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
63 * | Program Data & Heap |
64 * UTEXT --------> +------------------------------+ 0x00800000
65 * PFTEMP -------> | Empty Memory (*) | PTSIZE
67 * UTEMP --------> +------------------------------+ 0x00400000 --+
68 * | Empty Memory (*) | |
69 * | - - - - - - - - - - - - - - -| |
70 * | User STAB Data (optional) | PTSIZE
71 * USTABDATA ----> +------------------------------+ 0x00200000 |
72 * | Empty Memory (*) | |
73 * 0 ------------> +------------------------------+ --+
75 * (*) Note: The kernel ensures that "Invalid Memory" (ULIM) is *never*
76 * mapped. "Empty Memory" is normally unmapped, but user programs may
77 * map pages there if desired. ROS user programs map pages temporarily
82 // At IOPHYSMEM (640K) there is a 384K hole for I/O. From the kernel,
83 // IOPHYSMEM can be addressed at KERNBASE + IOPHYSMEM. The hole ends
84 // at physical address EXTPHYSMEM.
85 #define IOPHYSMEM 0x0A0000
86 #define VGAPHYSMEM 0x0A0000
87 #define DEVPHYSMEM 0x0C0000
88 #define BIOSPHYSMEM 0x0F0000
89 #define EXTPHYSMEM 0x100000
91 // Virtual page table. Entry PDX(VPT) in the PD contains a pointer to
92 // the page directory itself, thereby turning the PD into a page table,
93 // which maps all the PTEs containing the page mappings for the entire
94 // virtual address space into that 4 Meg region starting at VPT.
95 #define VPT (KERNBASE - PTSIZE)
97 #define KSTKSHIFT (PGSHIFT+3) // KSTKSIZE == 8*PGSIZE
98 #define KSTKSIZE (1 << KSTKSHIFT) // size of a kernel stack
99 #define ULIM (KSTACKTOP - PTSIZE)
102 * User read-only mappings! Anything below here til UTOP are readonly to user.
103 * They are global pages mapped in at env allocation time.
106 // Same as VPT but read-only for users
107 #define UVPT (ULIM - PTSIZE)
110 * Top of user VM. User can manipulate VA from UTOP-1 and down!
113 // Top of user-accessible VM
114 #define UTOP (UVPT - PTSIZE)
115 // Read-only, per-process shared info structures
118 // Read-write, per-process shared page for sending asynchronous
119 // syscalls to the kernel
120 #define UDATA (UTOP - PTSIZE)
122 // Read-write, global page. Shared by all processes. Can't be trusted.
123 #define UGDATA (UDATA - PGSIZE)
125 // Top of one-page user exception stack
126 #define UXSTACKTOP UGDATA
127 /* Limit of what is mmap()/munmap()-able */
128 #define UMAPTOP UXSTACKTOP
129 // Next page left invalid to guard against exception stack overflow; then:
130 // Top of normal user stack
131 #define USTACKTOP (UXSTACKTOP - 2*PGSIZE)
132 // Maximum stack depth preallocated to 1MB
133 #define USTACK_NUM_PAGES 256
134 // Next page left invalid to guard against stack overflow
135 // Maximum bottom of normal user stack
136 #define USTACKBOT (USTACKTOP - (USTACK_NUM_PAGES+1)*PGSIZE)
138 // Arbitrary boundary between the break and the start of
139 // memory returned by calls to mmap with addr = 0
140 #define BRK_END 0x20000000
142 // Where user programs generally begin
143 #define UTEXT (2*PTSIZE)
145 // Used for temporary page mappings. Typed 'void*' for convenience
146 #define UTEMP ((void*) PTSIZE)
147 // Used for temporary page mappings for the user page-fault handler
148 // (should not conflict with other temporary page mappings)
149 #define PFTEMP (UTEMP + PTSIZE - PGSIZE)
150 // The location of the user-level STABS data structure
151 #define USTABDATA (PTSIZE / 2)
154 #ifndef __ASSEMBLER__
157 * The page directory entry corresponding to the virtual address range
158 * [VPT, VPT + PTSIZE) points to the page directory itself. Thus, the page
159 * directory is treated as a page table as well as a page directory.
161 * One result of treating the page directory as a page table is that all PTEs
162 * can be accessed through a "virtual page table" at virtual address VPT (to
163 * which vpt is set in entry.S). The PTE for page number N is stored in
164 * vpt[N]. (It's worth drawing a diagram of this!)
166 * A second consequence is that the contents of the current page directory
167 * will always be available at virtual address (VPT + (VPT >> PGSHIFT)), to
168 * which vpd is set in entry.S.
172 #pragma cilnoremove("vpt_lock", "vpd_lock")
174 extern volatile uint32_t vpt_lock;
175 extern volatile uint32_t vpd_lock;
177 extern volatile pte_t SLOCKED(&vpt_lock) (COUNT(PTSIZE) SREADONLY vpt)[]; // VA of "virtual page table"
178 extern volatile pde_t SLOCKED(&vpd_lock) (COUNT(PTSIZE) SREADONLY vpd)[]; // VA of current page directory
180 #endif /* !__ASSEMBLER__ */
181 #endif /* !ROS_INC_MEMLAYOUT_H */