1 #ifndef ROS_INC_MEMLAYOUT_H
2 #define ROS_INC_MEMLAYOUT_H
5 #include <arch/types.h>
7 #endif /* not __ASSEMBLER__ */
10 * This file contains definitions for memory management in our OS,
11 * which are relevant to both the kernel and user-mode software.
15 * Virtual memory map: Permissions
18 * 4 Gig --------> +------------------------------+
20 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 * |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| RW/--
26 * | Remapped Physical Memory | RW/--
28 * KERNBASE -----> +------------------------------+ 0xc0000000
29 * | Cur. Page Table (Kern. RW) | RW/-- PTSIZE
30 * VPT,KSTACKTOP--> +------------------------------+ 0xbfc00000 --+
31 * | Kernel Stack | RW/-- KSTKSIZE |
32 * | - - - - - - - - - - - - - - -| PTSIZE
33 * | Invalid Memory (*) | --/-- |
34 * ULIM ----> +------------------------------+ 0xbf800000 --+
35 * | Cur. Page Table (User R-) | R-/R- PTSIZE
36 * UVPT ----> +------------------------------+ 0xbf400000 --+
37 * | Unmapped (expandable region) | |
39 * | Per-Process R/O Info | |
40 * UTOP, UINFO ----> +------------------------------+ 0xbf000000 --+
41 * | Unmapped (expandable region) | |
43 * | Per-Process R/W Data | |
44 * UDATA ----> +------------------------------+ 0xbec00000 --+
45 * | Global Shared R/W Data | RW/RW PGSIZE
46 * UXSTACKTOP,UGDATA ->+------------------------------+ 0xbebff000
47 * | User Exception Stack | RW/RW PGSIZE
48 * +------------------------------+ 0xbebfe000
49 * | Empty Memory (*) | --/-- PGSIZE
50 * USTACKTOP ---> +------------------------------+ 0xbebfd000
51 * | Normal User Stack | RW/RW PGSIZE
52 * +------------------------------+ 0xbebfc000
55 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59 * |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
60 * | Program Data & Heap |
61 * UTEXT --------> +------------------------------+ 0x00800000
62 * PFTEMP -------> | Empty Memory (*) | PTSIZE
64 * UTEMP --------> +------------------------------+ 0x00400000 --+
65 * | Empty Memory (*) | |
66 * | - - - - - - - - - - - - - - -| |
67 * | User STAB Data (optional) | PTSIZE
68 * USTABDATA ----> +------------------------------+ 0x00200000 |
69 * | Empty Memory (*) | |
70 * 0 ------------> +------------------------------+ --+
72 * (*) Note: The kernel ensures that "Invalid Memory" (ULIM) is *never*
73 * mapped. "Empty Memory" is normally unmapped, but user programs may
74 * map pages there if desired. ROS user programs map pages temporarily
79 // All physical memory mapped at this address
80 #define KERNBASE 0xC0000000
82 // Use this if needed in annotations
83 #define IVY_KERNBASE (0xC000U << 16)
85 // At IOPHYSMEM (640K) there is a 384K hole for I/O. From the kernel,
86 // IOPHYSMEM can be addressed at KERNBASE + IOPHYSMEM. The hole ends
87 // at physical address EXTPHYSMEM.
88 #define IOPHYSMEM 0x0A0000
89 #define VGAPHYSMEM 0x0A0000
90 #define DEVPHYSMEM 0x0C0000
91 #define BIOSPHYSMEM 0x0F0000
92 #define EXTPHYSMEM 0x100000
94 // Virtual page table. Entry PDX(VPT) in the PD contains a pointer to
95 // the page directory itself, thereby turning the PD into a page table,
96 // which maps all the PTEs containing the page mappings for the entire
97 // virtual address space into that 4 Meg region starting at VPT.
98 #define VPT (KERNBASE - PTSIZE)
100 #define KSTKSHIFT (PGSHIFT+3) // KSTKSIZE == 8*PGSIZE
101 #define KSTKSIZE (1 << KSTKSHIFT) // size of a kernel stack
102 #define ULIM (KSTACKTOP - PTSIZE)
105 * User read-only mappings! Anything below here til UTOP are readonly to user.
106 * They are global pages mapped in at env allocation time.
109 // Same as VPT but read-only for users
110 #define UVPT (ULIM - PTSIZE)
113 * Top of user VM. User can manipulate VA from UTOP-1 and down!
116 // Top of user-accessible VM
117 #define UTOP (UVPT - PTSIZE)
118 // Read-only, per-process shared info structures
121 // Read-write, per-process shared page for sending asynchronous
122 // syscalls to the kernel
123 #define UDATA (UTOP - PTSIZE)
125 // Read-write, global page. Shared by all processes. Can't be trusted.
126 #define UGDATA (UDATA - PGSIZE)
128 // Top of one-page user exception stack
129 #define UXSTACKTOP UGDATA
130 // Next page left invalid to guard against exception stack overflow; then:
131 // Top of normal user stack
132 #define USTACKTOP (UXSTACKTOP - 2*PGSIZE)
134 // Where user programs generally begin
135 #define UTEXT (2*PTSIZE)
137 // Used for temporary page mappings. Typed 'void*' for convenience
138 #define UTEMP ((void*) PTSIZE)
139 // Used for temporary page mappings for the user page-fault handler
140 // (should not conflict with other temporary page mappings)
141 #define PFTEMP (UTEMP + PTSIZE - PGSIZE)
142 // The location of the user-level STABS data structure
143 #define USTABDATA (PTSIZE / 2)
146 #ifndef __ASSEMBLER__
149 * The page directory entry corresponding to the virtual address range
150 * [VPT, VPT + PTSIZE) points to the page directory itself. Thus, the page
151 * directory is treated as a page table as well as a page directory.
153 * One result of treating the page directory as a page table is that all PTEs
154 * can be accessed through a "virtual page table" at virtual address VPT (to
155 * which vpt is set in entry.S). The PTE for page number N is stored in
156 * vpt[N]. (It's worth drawing a diagram of this!)
158 * A second consequence is that the contents of the current page directory
159 * will always be available at virtual address (VPT + (VPT >> PGSHIFT)), to
160 * which vpd is set in entry.S.
162 typedef uint32_t pte_t;
163 typedef uint32_t pde_t;
165 extern volatile pte_t (COUNT(PTSIZE) vpt)[]; // VA of "virtual page table"
166 extern volatile pde_t (COUNT(PTSIZE) vpd)[]; // VA of current page directory
168 #endif /* !__ASSEMBLER__ */
169 #endif /* !ROS_INC_MEMLAYOUT_H */