4 #include <minix/callnr.h>
6 #include <minix/config.h>
7 #include <minix/const.h>
9 #include <minix/endpoint.h>
10 #include <minix/minlib.h>
11 #include <minix/type.h>
12 #include <minix/ipc.h>
13 #include <minix/sysutil.h>
14 #include <minix/syslib.h>
15 #include <minix/safecopies.h>
16 #include <minix/cpufeature.h>
17 #include <minix/bitmap.h>
18 #include <minix/debug.h>
33 #include "sanitycheck.h"
35 static int vm_self_pages
;
37 /* PDE used to map in kernel, kernel physical address. */
38 #define MAX_PAGEDIR_PDES 5
43 u32_t
*page_directories
;
44 } pagedir_mappings
[MAX_PAGEDIR_PDES
];
46 static multiboot_module_t
*kern_mb_mod
= NULL
;
47 static size_t kern_size
= 0;
48 static int kern_start_pde
= -1;
50 /* big page size available in hardware? */
51 static int bigpage_ok
= 1;
53 /* Our process table entry. */
54 struct vmproc
*vmprocess
= &vmproc
[VM_PROC_NR
];
56 /* Spare memory, ready to go after initialization, to avoid a
57 * circular dependency on allocating memory and writing it into VM's
61 #define SPAREPAGES 200
62 #define STATIC_SPAREPAGES 190
65 # define SPAREPAGES 150
66 # define STATIC_SPAREPAGES 140
68 # define SPAREPAGES 20
69 # define STATIC_SPAREPAGES 15
74 static u32_t global_bit
= 0;
77 #define SPAREPAGEDIRS 1
78 #define STATIC_SPAREPAGEDIRS 1
80 int missing_sparedirs
= SPAREPAGEDIRS
;
84 } sparepagedirs
[SPAREPAGEDIRS
];
86 #define is_staticaddr(v) ((vir_bytes) (v) < VM_OWN_HEAPSTART)
88 #define MAX_KERNMAPPINGS 10
90 phys_bytes phys_addr
; /* Physical addr. */
91 phys_bytes len
; /* Length in bytes. */
92 vir_bytes vir_addr
; /* Offset in page table. */
94 } kern_mappings
[MAX_KERNMAPPINGS
];
97 /* Clicks must be pages, as
98 * - they must be page aligned to map them
99 * - they must be a multiple of the page size
100 * - it's inconvenient to have them bigger than pages, because we often want
102 * May as well require them to be equal then.
104 #if CLICK_SIZE != VM_PAGE_SIZE
105 #error CLICK_SIZE must be page size.
108 static void *spare_pagequeue
;
109 static char static_sparepages
[VM_PAGE_SIZE
*STATIC_SPAREPAGES
]
110 __aligned(VM_PAGE_SIZE
);
113 static char static_sparepagedirs
[ARCH_PAGEDIR_SIZE
*STATIC_SPAREPAGEDIRS
+ ARCH_PAGEDIR_SIZE
] __aligned(ARCH_PAGEDIR_SIZE
);
116 void pt_assert(pt_t
*pt
)
120 if((sys_vmctl(SELF
, VMCTL_FLUSHTLB
, 0)) != OK
) {
121 panic("VMCTL_FLUSHTLB failed");
123 sys_physcopy(NONE
, pt
->pt_dir_phys
, SELF
, (vir_bytes
) dir
, sizeof(dir
), 0);
124 assert(!memcmp(dir
, pt
->pt_dir
, sizeof(dir
)));
128 /*===========================================================================*
130 *===========================================================================*/
131 void pt_sanitycheck(pt_t
*pt
, const char *file
, int line
)
133 /* Basic pt sanity check. */
137 MYASSERT(pt
->pt_dir
);
138 MYASSERT(pt
->pt_dir_phys
);
140 for(slot
= 0; slot
< ELEMENTS(vmproc
); slot
++) {
141 if(pt
== &vmproc
[slot
].vm_pt
)
145 if(slot
>= ELEMENTS(vmproc
)) {
146 panic("pt_sanitycheck: passed pt not in any proc");
149 MYASSERT(usedpages_add(pt
->pt_dir_phys
, VM_PAGE_SIZE
) == OK
);
153 /*===========================================================================*
155 *===========================================================================*/
156 static u32_t
findhole(int pages
)
158 /* Find a space in the virtual address space of VM. */
160 int pde
= 0, try_restart
;
161 static void *lastv
= 0;
162 pt_t
*pt
= &vmprocess
->vm_pt
;
163 vir_bytes vmin
, vmax
;
164 u32_t holev
= NO_MEM
;
167 vmin
= VM_OWN_MMAPBASE
;
168 vmax
= VM_OWN_MMAPTOP
;
170 /* Input sanity check. */
171 assert(vmin
+ VM_PAGE_SIZE
>= vmin
);
172 assert(vmax
>= vmin
+ VM_PAGE_SIZE
);
173 assert((vmin
% VM_PAGE_SIZE
) == 0);
174 assert((vmax
% VM_PAGE_SIZE
) == 0);
177 curv
= (u32_t
) lastv
;
178 if(curv
< vmin
|| curv
>= vmax
)
183 /* Start looking for a free page starting at vmin. */
187 assert(curv
>= vmin
);
190 pde
= ARCH_VM_PDE(curv
);
191 pte
= ARCH_VM_PTE(curv
);
193 if((pt
->pt_dir
[pde
] & ARCH_VM_PDE_PRESENT
) &&
194 (pt
->pt_pt
[pde
][pte
] & ARCH_VM_PTE_PRESENT
)) {
195 /* there is a page here - so keep looking for holes */
199 /* there is no page here - so we have a hole, a bigger
200 * one if we already had one
202 if(holev
== NO_MEM
) {
207 assert(holesize
> 0);
208 assert(holesize
<= pages
);
210 /* if it's big enough, return it */
211 if(holesize
== pages
) {
212 lastv
= (void*) (curv
+ VM_PAGE_SIZE
);
219 /* if we reached the limit, start scanning from the beginning if
220 * we haven't looked there yet
222 if(curv
>= vmax
&& try_restart
) {
228 printf("VM: out of virtual address space in vm\n");
233 /*===========================================================================*
235 *===========================================================================*/
236 void vm_freepages(vir_bytes vir
, int pages
)
238 assert(!(vir
% VM_PAGE_SIZE
));
240 if(is_staticaddr(vir
)) {
241 printf("VM: not freeing static page\n");
245 if(pt_writemap(vmprocess
, &vmprocess
->vm_pt
, vir
,
246 MAP_NONE
, pages
*VM_PAGE_SIZE
, 0,
247 WMF_OVERWRITE
| WMF_FREE
) != OK
)
248 panic("vm_freepages: pt_writemap failed");
253 /* If SANITYCHECKS are on, flush tlb so accessing freed pages is
254 * always trapped, also if not in tlb.
256 if((sys_vmctl(SELF
, VMCTL_FLUSHTLB
, 0)) != OK
) {
257 panic("VMCTL_FLUSHTLB failed");
262 /*===========================================================================*
264 *===========================================================================*/
265 static void *vm_getsparepage(phys_bytes
*phys
)
268 if(reservedqueue_alloc(spare_pagequeue
, phys
, &ptr
) != OK
) {
275 /*===========================================================================*
276 * vm_getsparepagedir *
277 *===========================================================================*/
278 static void *vm_getsparepagedir(phys_bytes
*phys
)
281 assert(missing_sparedirs
>= 0 && missing_sparedirs
<= SPAREPAGEDIRS
);
282 for(s
= 0; s
< SPAREPAGEDIRS
; s
++) {
283 if(sparepagedirs
[s
].pagedir
) {
285 sp
= sparepagedirs
[s
].pagedir
;
286 *phys
= sparepagedirs
[s
].phys
;
287 sparepagedirs
[s
].pagedir
= NULL
;
289 assert(missing_sparedirs
>= 0 && missing_sparedirs
<= SPAREPAGEDIRS
);
296 void *vm_mappages(phys_bytes p
, int pages
)
300 pt_t
*pt
= &vmprocess
->vm_pt
;
302 /* Where in our virtual address space can we put it? */
303 loc
= findhole(pages
);
305 printf("vm_mappages: findhole failed\n");
309 /* Map this page into our address space. */
310 if((r
=pt_writemap(vmprocess
, pt
, loc
, p
, VM_PAGE_SIZE
*pages
,
311 ARCH_VM_PTE_PRESENT
| ARCH_VM_PTE_USER
| ARCH_VM_PTE_RW
316 printf("vm_mappages writemap failed\n");
320 if((r
=sys_vmctl(SELF
, VMCTL_FLUSHTLB
, 0)) != OK
) {
321 panic("VMCTL_FLUSHTLB failed: %d", r
);
329 static int pt_init_done
;
331 /*===========================================================================*
333 *===========================================================================*/
334 void *vm_allocpages(phys_bytes
*phys
, int reason
, int pages
)
336 /* Allocate a page for use by VM itself. */
338 static int level
= 0;
342 assert(reason
>= 0 && reason
< VMP_CATEGORIES
);
351 if((level
> 1) || !pt_init_done
) {
354 if(pages
== 1) s
=vm_getsparepage(phys
);
355 else if(pages
== 4) s
=vm_getsparepagedir(phys
);
356 else panic("%d pages", pages
);
361 printf("VM: warning: out of spare pages\n");
363 if(!is_staticaddr(s
)) vm_self_pages
++;
368 if (reason
== VMP_PAGEDIR
) {
369 mem_flags
|= PAF_ALIGN16K
;
373 /* Allocate page of memory for use by VM. As VM
374 * is trusted, we don't have to pre-clear it.
376 if((newpage
= alloc_mem(pages
, mem_flags
)) == NO_MEM
) {
378 printf("VM: vm_allocpage: alloc_mem failed\n");
382 *phys
= CLICK2ABS(newpage
);
384 if(!(ret
= vm_mappages(*phys
, pages
))) {
386 printf("VM: vm_allocpage: vm_mappages failed\n");
396 void *vm_allocpage(phys_bytes
*phys
, int reason
)
398 return vm_allocpages(phys
, reason
, 1);
401 /*===========================================================================*
403 *===========================================================================*/
404 void vm_pagelock(void *vir
, int lockflag
)
406 /* Mark a page allocated by vm_allocpage() unwritable, i.e. only for VM. */
407 vir_bytes m
= (vir_bytes
) vir
;
409 u32_t flags
= ARCH_VM_PTE_PRESENT
| ARCH_VM_PTE_USER
;
412 pt
= &vmprocess
->vm_pt
;
414 assert(!(m
% VM_PAGE_SIZE
));
417 flags
|= ARCH_VM_PTE_RW
;
420 flags
|= ARCH_VM_PTE_RO
;
422 flags
|= ARM_VM_PTE_CACHED
;
426 if((r
=pt_writemap(vmprocess
, pt
, m
, 0, VM_PAGE_SIZE
,
427 flags
, WMF_OVERWRITE
| WMF_WRITEFLAGSONLY
)) != OK
) {
428 panic("vm_lockpage: pt_writemap failed");
431 if((r
=sys_vmctl(SELF
, VMCTL_FLUSHTLB
, 0)) != OK
) {
432 panic("VMCTL_FLUSHTLB failed: %d", r
);
438 /*===========================================================================*
440 *===========================================================================*/
441 int vm_addrok(void *vir
, int writeflag
)
443 pt_t
*pt
= &vmprocess
->vm_pt
;
445 vir_bytes v
= (vir_bytes
) vir
;
447 pde
= ARCH_VM_PDE(v
);
448 pte
= ARCH_VM_PTE(v
);
450 if(!(pt
->pt_dir
[pde
] & ARCH_VM_PDE_PRESENT
)) {
451 printf("addr not ok: missing pde %d\n", pde
);
455 #if defined(__i386__)
457 !(pt
->pt_dir
[pde
] & ARCH_VM_PTE_RW
)) {
458 printf("addr not ok: pde %d present but pde unwritable\n", pde
);
461 #elif defined(__arm__)
463 (pt
->pt_dir
[pde
] & ARCH_VM_PTE_RO
)) {
464 printf("addr not ok: pde %d present but pde unwritable\n", pde
);
469 if(!(pt
->pt_pt
[pde
][pte
] & ARCH_VM_PTE_PRESENT
)) {
470 printf("addr not ok: missing pde %d / pte %d\n",
475 #if defined(__i386__)
477 !(pt
->pt_pt
[pde
][pte
] & ARCH_VM_PTE_RW
)) {
478 printf("addr not ok: pde %d / pte %d present but unwritable\n",
480 #elif defined(__arm__)
482 (pt
->pt_pt
[pde
][pte
] & ARCH_VM_PTE_RO
)) {
483 printf("addr not ok: pde %d / pte %d present but unwritable\n",
492 /*===========================================================================*
494 *===========================================================================*/
495 static int pt_ptalloc(pt_t
*pt
, int pde
, u32_t flags
)
497 /* Allocate a page table and write its address into the page directory. */
502 /* Argument must make sense. */
503 assert(pde
>= 0 && pde
< ARCH_VM_DIR_ENTRIES
);
504 assert(!(flags
& ~(PTF_ALLFLAGS
)));
506 /* We don't expect to overwrite page directory entry, nor
507 * storage for the page table.
509 assert(!(pt
->pt_dir
[pde
] & ARCH_VM_PDE_PRESENT
));
510 assert(!pt
->pt_pt
[pde
]);
512 /* Get storage for the page table. The allocation call may in fact
513 * recursively create the directory entry as a side effect. In that
514 * case, we free the newly allocated page and do nothing else.
516 if (!(p
= vm_allocpage(&pt_phys
, VMP_PAGETABLE
)))
518 if (pt
->pt_pt
[pde
]) {
519 vm_freepages((vir_bytes
) p
, 1);
520 assert(pt
->pt_pt
[pde
]);
525 for(i
= 0; i
< ARCH_VM_PT_ENTRIES
; i
++)
526 pt
->pt_pt
[pde
][i
] = 0; /* Empty entry. */
528 /* Make page directory entry.
529 * The PDE is always 'present,' 'writable,' and 'user accessible,'
530 * relying on the PTE for protection.
532 #if defined(__i386__)
533 pt
->pt_dir
[pde
] = (pt_phys
& ARCH_VM_ADDR_MASK
) | flags
534 | ARCH_VM_PDE_PRESENT
| ARCH_VM_PTE_USER
| ARCH_VM_PTE_RW
;
535 #elif defined(__arm__)
536 pt
->pt_dir
[pde
] = (pt_phys
& ARCH_VM_PDE_MASK
)
537 | ARCH_VM_PDE_PRESENT
| ARM_VM_PDE_DOMAIN
; //LSC FIXME
543 /*===========================================================================*
544 * pt_ptalloc_in_range *
545 *===========================================================================*/
546 int pt_ptalloc_in_range(pt_t
*pt
, vir_bytes start
, vir_bytes end
,
547 u32_t flags
, int verify
)
549 /* Allocate all the page tables in the range specified. */
550 int pde
, first_pde
, last_pde
;
552 first_pde
= ARCH_VM_PDE(start
);
553 last_pde
= ARCH_VM_PDE(end
-1);
555 assert(first_pde
>= 0);
556 assert(last_pde
< ARCH_VM_DIR_ENTRIES
);
558 /* Scan all page-directory entries in the range. */
559 for(pde
= first_pde
; pde
<= last_pde
; pde
++) {
560 assert(!(pt
->pt_dir
[pde
] & ARCH_VM_BIGPAGE
));
561 if(!(pt
->pt_dir
[pde
] & ARCH_VM_PDE_PRESENT
)) {
564 printf("pt_ptalloc_in_range: no pde %d\n", pde
);
567 assert(!pt
->pt_dir
[pde
]);
568 if((r
=pt_ptalloc(pt
, pde
, flags
)) != OK
) {
569 /* Couldn't do (complete) mapping.
570 * Don't bother freeing any previously
571 * allocated page tables, they're
572 * still writable, don't point to nonsense,
573 * and pt_ptalloc leaves the directory
574 * and other data in a consistent state.
578 assert(pt
->pt_pt
[pde
]);
580 assert(pt
->pt_pt
[pde
]);
581 assert(pt
->pt_dir
[pde
]);
582 assert(pt
->pt_dir
[pde
] & ARCH_VM_PDE_PRESENT
);
588 static const char *ptestr(u32_t pte
)
590 #define FLAG(constant, name) { \
591 if(pte & (constant)) { strcat(str, name); strcat(str, " "); } \
595 if(!(pte
& ARCH_VM_PTE_PRESENT
)) {
596 return "not present";
599 #if defined(__i386__)
600 FLAG(ARCH_VM_PTE_RW
, "W");
601 #elif defined(__arm__)
602 if(pte
& ARCH_VM_PTE_RO
) {
608 FLAG(ARCH_VM_PTE_USER
, "U");
609 #if defined(__i386__)
610 FLAG(I386_VM_PWT
, "PWT");
611 FLAG(I386_VM_PCD
, "PCD");
612 FLAG(I386_VM_ACC
, "ACC");
613 FLAG(I386_VM_DIRTY
, "DIRTY");
614 FLAG(I386_VM_PS
, "PS");
615 FLAG(I386_VM_GLOBAL
, "G");
616 FLAG(I386_VM_PTAVAIL1
, "AV1");
617 FLAG(I386_VM_PTAVAIL2
, "AV2");
618 FLAG(I386_VM_PTAVAIL3
, "AV3");
619 #elif defined(__arm__)
620 FLAG(ARM_VM_PTE_SUPER
, "S");
621 FLAG(ARM_VM_PTE_S
, "SH");
622 FLAG(ARM_VM_PTE_WB
, "WB");
623 FLAG(ARM_VM_PTE_WT
, "WT");
629 /*===========================================================================*
631 *===========================================================================*/
632 int pt_map_in_range(struct vmproc
*src_vmp
, struct vmproc
*dst_vmp
,
633 vir_bytes start
, vir_bytes end
)
635 /* Transfer all the mappings from the pt of the source process to the pt of
636 * the destination process in the range specified.
642 pt
= &src_vmp
->vm_pt
;
643 dst_pt
= &dst_vmp
->vm_pt
;
645 end
= end
? end
: VM_DATATOP
;
646 assert(start
% VM_PAGE_SIZE
== 0);
647 assert(end
% VM_PAGE_SIZE
== 0);
649 assert( /* ARCH_VM_PDE(start) >= 0 && */ start
<= end
);
650 assert(ARCH_VM_PDE(end
) < ARCH_VM_DIR_ENTRIES
);
653 printf("VM: pt_map_in_range: src = %d, dst = %d\n",
654 src_vmp
->vm_endpoint
, dst_vmp
->vm_endpoint
);
655 printf("VM: pt_map_in_range: transferring from 0x%08x (pde %d pte %d) to 0x%08x (pde %d pte %d)\n",
656 start
, ARCH_VM_PDE(start
), ARCH_VM_PTE(start
),
657 end
, ARCH_VM_PDE(end
), ARCH_VM_PTE(end
));
660 /* Scan all page-table entries in the range. */
661 for(viraddr
= start
; viraddr
<= end
; viraddr
+= VM_PAGE_SIZE
) {
662 pde
= ARCH_VM_PDE(viraddr
);
663 if(!(pt
->pt_dir
[pde
] & ARCH_VM_PDE_PRESENT
)) {
664 if(viraddr
== VM_DATATOP
) break;
667 pte
= ARCH_VM_PTE(viraddr
);
668 if(!(pt
->pt_pt
[pde
][pte
] & ARCH_VM_PTE_PRESENT
)) {
669 if(viraddr
== VM_DATATOP
) break;
673 /* Transfer the mapping. */
674 dst_pt
->pt_pt
[pde
][pte
] = pt
->pt_pt
[pde
][pte
];
675 assert(dst_pt
->pt_pt
[pde
]);
677 if(viraddr
== VM_DATATOP
) break;
683 /*===========================================================================*
685 *===========================================================================*/
686 int pt_ptmap(struct vmproc
*src_vmp
, struct vmproc
*dst_vmp
)
688 /* Transfer mappings to page dir and page tables from source process and
689 * destination process.
696 pt
= &src_vmp
->vm_pt
;
699 printf("VM: pt_ptmap: src = %d, dst = %d\n",
700 src_vmp
->vm_endpoint
, dst_vmp
->vm_endpoint
);
703 /* Transfer mapping to the page directory. */
704 viraddr
= (vir_bytes
) pt
->pt_dir
;
705 physaddr
= pt
->pt_dir_phys
& ARCH_VM_ADDR_MASK
;
706 #if defined(__i386__)
707 if((r
=pt_writemap(dst_vmp
, &dst_vmp
->vm_pt
, viraddr
, physaddr
, VM_PAGE_SIZE
,
708 ARCH_VM_PTE_PRESENT
| ARCH_VM_PTE_USER
| ARCH_VM_PTE_RW
,
709 #elif defined(__arm__)
710 if((r
=pt_writemap(dst_vmp
, &dst_vmp
->vm_pt
, viraddr
, physaddr
, ARCH_PAGEDIR_SIZE
,
711 ARCH_VM_PTE_PRESENT
| ARCH_VM_PTE_USER
|
714 WMF_OVERWRITE
)) != OK
) {
718 printf("VM: pt_ptmap: transferred mapping to page dir: 0x%08x (0x%08x)\n",
722 /* Scan all non-reserved page-directory entries. */
723 for(pde
=0; pde
< kern_start_pde
; pde
++) {
724 if(!(pt
->pt_dir
[pde
] & ARCH_VM_PDE_PRESENT
)) {
728 if(!pt
->pt_pt
[pde
]) { panic("pde %d empty\n", pde
); }
730 /* Transfer mapping to the page table. */
731 viraddr
= (vir_bytes
) pt
->pt_pt
[pde
];
732 #if defined(__i386__)
733 physaddr
= pt
->pt_dir
[pde
] & ARCH_VM_ADDR_MASK
;
734 #elif defined(__arm__)
735 physaddr
= pt
->pt_dir
[pde
] & ARCH_VM_PDE_MASK
;
738 if((r
=pt_writemap(dst_vmp
, &dst_vmp
->vm_pt
, viraddr
, physaddr
, VM_PAGE_SIZE
,
739 ARCH_VM_PTE_PRESENT
| ARCH_VM_PTE_USER
| ARCH_VM_PTE_RW
744 WMF_OVERWRITE
)) != OK
) {
752 void pt_clearmapcache(void)
754 /* Make sure kernel will invalidate tlb when using current
755 * pagetable (i.e. vm's) to make new mappings before new cr3
758 if(sys_vmctl(SELF
, VMCTL_CLEARMAPCACHE
, 0) != OK
)
759 panic("VMCTL_CLEARMAPCACHE failed");
762 int pt_writable(struct vmproc
*vmp
, vir_bytes v
)
765 pt_t
*pt
= &vmp
->vm_pt
;
766 assert(!(v
% VM_PAGE_SIZE
));
767 int pde
= ARCH_VM_PDE(v
);
768 int pte
= ARCH_VM_PTE(v
);
770 assert(pt
->pt_dir
[pde
] & ARCH_VM_PDE_PRESENT
);
771 assert(pt
->pt_pt
[pde
]);
773 entry
= pt
->pt_pt
[pde
][pte
];
775 #if defined(__i386__)
776 return((entry
& PTF_WRITE
) ? 1 : 0);
777 #elif defined(__arm__)
778 return((entry
& ARCH_VM_PTE_RO
) ? 0 : 1);
782 /*===========================================================================*
784 *===========================================================================*/
785 int pt_writemap(struct vmproc
* vmp
,
793 /* Write mapping into page table. Allocate a new page table if necessary. */
794 /* Page directory and table entries for this virtual address. */
800 int vminhibit_clear
= 0;
802 * don't do it everytime, stop the process only on the first change and
803 * resume the execution on the last change. Do in a wrapper of this
806 if (vmp
&& vmp
->vm_endpoint
!= NONE
&& vmp
->vm_endpoint
!= VM_PROC_NR
&&
807 !(vmp
->vm_flags
& VMF_EXITING
)) {
808 sys_vmctl(vmp
->vm_endpoint
, VMCTL_VMINHIBIT_SET
, 0);
813 if(writemapflags
& WMF_VERIFY
)
816 assert(!(bytes
% VM_PAGE_SIZE
));
817 assert(!(flags
& ~(PTF_ALLFLAGS
)));
819 pages
= bytes
/ VM_PAGE_SIZE
;
821 /* MAP_NONE means to clear the mapping. It doesn't matter
822 * what's actually written into the PTE if PRESENT
823 * isn't on, so we can just write MAP_NONE into it.
825 assert(physaddr
== MAP_NONE
|| (flags
& ARCH_VM_PTE_PRESENT
));
826 assert(physaddr
!= MAP_NONE
|| !flags
);
828 /* First make sure all the necessary page tables are allocated,
829 * before we start writing in any of them, because it's a pain
830 * to undo our work properly.
832 ret
= pt_ptalloc_in_range(pt
, v
, v
+ VM_PAGE_SIZE
*pages
, flags
, verify
);
834 printf("VM: writemap: pt_ptalloc_in_range failed\n");
838 /* Now write in them. */
839 for(p
= 0; p
< pages
; p
++) {
841 int pde
= ARCH_VM_PDE(v
);
842 int pte
= ARCH_VM_PTE(v
);
844 assert(!(v
% VM_PAGE_SIZE
));
845 assert(pte
>= 0 && pte
< ARCH_VM_PT_ENTRIES
);
846 assert(pde
>= 0 && pde
< ARCH_VM_DIR_ENTRIES
);
848 /* Page table has to be there. */
849 assert(pt
->pt_dir
[pde
] & ARCH_VM_PDE_PRESENT
);
851 /* We do not expect it to be a bigpage. */
852 assert(!(pt
->pt_dir
[pde
] & ARCH_VM_BIGPAGE
));
854 /* Make sure page directory entry for this page table
855 * is marked present and page table entry is available.
857 assert(pt
->pt_pt
[pde
]);
859 if(writemapflags
& (WMF_WRITEFLAGSONLY
|WMF_FREE
)) {
860 #if defined(__i386__)
861 physaddr
= pt
->pt_pt
[pde
][pte
] & ARCH_VM_ADDR_MASK
;
862 #elif defined(__arm__)
863 physaddr
= pt
->pt_pt
[pde
][pte
] & ARM_VM_PTE_MASK
;
867 if(writemapflags
& WMF_FREE
) {
868 free_mem(ABS2CLICK(physaddr
), 1);
871 /* Entry we will write. */
872 #if defined(__i386__)
873 entry
= (physaddr
& ARCH_VM_ADDR_MASK
) | flags
;
874 #elif defined(__arm__)
875 entry
= (physaddr
& ARM_VM_PTE_MASK
) | flags
;
880 maskedentry
= pt
->pt_pt
[pde
][pte
];
881 #if defined(__i386__)
882 maskedentry
&= ~(I386_VM_ACC
|I386_VM_DIRTY
);
884 /* Verify pagetable entry. */
885 #if defined(__i386__)
886 if(entry
& ARCH_VM_PTE_RW
) {
887 /* If we expect a writable page, allow a readonly page. */
888 maskedentry
|= ARCH_VM_PTE_RW
;
890 #elif defined(__arm__)
891 if(!(entry
& ARCH_VM_PTE_RO
)) {
892 /* If we expect a writable page, allow a readonly page. */
893 maskedentry
&= ~ARCH_VM_PTE_RO
;
895 maskedentry
&= ~(ARM_VM_PTE_WB
|ARM_VM_PTE_WT
);
897 if(maskedentry
!= entry
) {
898 printf("pt_writemap: mismatch: ");
899 #if defined(__i386__)
900 if((entry
& ARCH_VM_ADDR_MASK
) !=
901 (maskedentry
& ARCH_VM_ADDR_MASK
)) {
902 #elif defined(__arm__)
903 if((entry
& ARM_VM_PTE_MASK
) !=
904 (maskedentry
& ARM_VM_PTE_MASK
)) {
906 printf("pt_writemap: physaddr mismatch (0x%lx, 0x%lx); ",
907 (long)entry
, (long)maskedentry
);
908 } else printf("phys ok; ");
909 printf(" flags: found %s; ",
910 ptestr(pt
->pt_pt
[pde
][pte
]));
911 printf(" masked %s; ",
912 ptestr(maskedentry
));
913 printf(" expected %s\n", ptestr(entry
));
914 printf("found 0x%x, wanted 0x%x\n",
915 pt
->pt_pt
[pde
][pte
], entry
);
920 /* Write pagetable entry. */
921 pt
->pt_pt
[pde
][pte
] = entry
;
924 physaddr
+= VM_PAGE_SIZE
;
931 if (vminhibit_clear
) {
932 assert(vmp
&& vmp
->vm_endpoint
!= NONE
&& vmp
->vm_endpoint
!= VM_PROC_NR
&&
933 !(vmp
->vm_flags
& VMF_EXITING
));
934 sys_vmctl(vmp
->vm_endpoint
, VMCTL_VMINHIBIT_CLEAR
, 0);
941 /*===========================================================================*
943 *===========================================================================*/
944 int pt_checkrange(pt_t
*pt
, vir_bytes v
, size_t bytes
,
949 assert(!(bytes
% VM_PAGE_SIZE
));
951 pages
= bytes
/ VM_PAGE_SIZE
;
953 for(p
= 0; p
< pages
; p
++) {
954 int pde
= ARCH_VM_PDE(v
);
955 int pte
= ARCH_VM_PTE(v
);
957 assert(!(v
% VM_PAGE_SIZE
));
958 assert(pte
>= 0 && pte
< ARCH_VM_PT_ENTRIES
);
959 assert(pde
>= 0 && pde
< ARCH_VM_DIR_ENTRIES
);
961 /* Page table has to be there. */
962 if(!(pt
->pt_dir
[pde
] & ARCH_VM_PDE_PRESENT
))
965 /* Make sure page directory entry for this page table
966 * is marked present and page table entry is available.
968 assert((pt
->pt_dir
[pde
] & ARCH_VM_PDE_PRESENT
) && pt
->pt_pt
[pde
]);
970 if(!(pt
->pt_pt
[pde
][pte
] & ARCH_VM_PTE_PRESENT
)) {
974 #if defined(__i386__)
975 if(write
&& !(pt
->pt_pt
[pde
][pte
] & ARCH_VM_PTE_RW
)) {
976 #elif defined(__arm__)
977 if(write
&& (pt
->pt_pt
[pde
][pte
] & ARCH_VM_PTE_RO
)) {
988 /*===========================================================================*
990 *===========================================================================*/
993 /* Allocate a pagetable root. Allocate a page-aligned page directory
994 * and set them to 0 (indicating no page tables are allocated). Lookup
995 * its physical address as we'll need that in the future. Verify it's
1000 /* Don't ever re-allocate/re-move a certain process slot's
1001 * page directory once it's been created. This is a fraction
1002 * faster, but also avoids having to invalidate the page
1003 * mappings from in-kernel page tables pointing to
1004 * the page directories (the page_directories data).
1007 !(pt
->pt_dir
= vm_allocpages((phys_bytes
*)&pt
->pt_dir_phys
,
1008 VMP_PAGEDIR
, ARCH_PAGEDIR_SIZE
/VM_PAGE_SIZE
))) {
1012 assert(!((u32_t
)pt
->pt_dir_phys
% ARCH_PAGEDIR_SIZE
));
1014 for(i
= 0; i
< ARCH_VM_DIR_ENTRIES
; i
++) {
1015 pt
->pt_dir
[i
] = 0; /* invalid entry (PRESENT bit = 0) */
1016 pt
->pt_pt
[i
] = NULL
;
1019 /* Where to start looking for free virtual address space? */
1022 /* Map in kernel. */
1023 if((r
=pt_mapkernel(pt
)) != OK
)
1029 static int freepde(void)
1031 int p
= kernel_boot_info
.freepde_start
++;
1032 assert(kernel_boot_info
.freepde_start
< ARCH_VM_DIR_ENTRIES
);
1036 void pt_allocate_kernel_mapped_pagetables(void)
1038 /* Reserve PDEs available for mapping in the page directories. */
1040 for(pd
= 0; pd
< MAX_PAGEDIR_PDES
; pd
++) {
1041 struct pdm
*pdm
= &pagedir_mappings
[pd
];
1043 pdm
->pdeno
= freepde();
1048 /* Allocate us a page table in which to
1049 * remember page directory pointers.
1051 if(!(pdm
->page_directories
=
1052 vm_allocpage(&ph
, VMP_PAGETABLE
))) {
1053 panic("no virt addr for vm mappings");
1055 memset(pdm
->page_directories
, 0, VM_PAGE_SIZE
);
1058 #if defined(__i386__)
1059 pdm
->val
= (ph
& ARCH_VM_ADDR_MASK
) |
1060 ARCH_VM_PDE_PRESENT
| ARCH_VM_PTE_RW
;
1061 #elif defined(__arm__)
1062 pdm
->val
= (ph
& ARCH_VM_PDE_MASK
)
1063 | ARCH_VM_PDE_PRESENT
1065 | ARM_VM_PDE_DOMAIN
; //LSC FIXME
1070 static void pt_copy(pt_t
*dst
, pt_t
*src
)
1073 for(pde
=0; pde
< kern_start_pde
; pde
++) {
1074 if(!(src
->pt_dir
[pde
] & ARCH_VM_PDE_PRESENT
)) {
1077 assert(!(src
->pt_dir
[pde
] & ARCH_VM_BIGPAGE
));
1078 if(!src
->pt_pt
[pde
]) { panic("pde %d empty\n", pde
); }
1079 if(pt_ptalloc(dst
, pde
, 0) != OK
)
1080 panic("pt_ptalloc failed");
1081 memcpy(dst
->pt_pt
[pde
], src
->pt_pt
[pde
],
1082 ARCH_VM_PT_ENTRIES
* sizeof(*dst
->pt_pt
[pde
]));
1086 /*===========================================================================*
1088 *===========================================================================*/
1091 pt_t
*newpt
, newpt_dyn
;
1094 vir_bytes sparepages_mem
;
1095 #if defined(__arm__)
1096 vir_bytes sparepagedirs_mem
;
1098 static u32_t currentpagedir
[ARCH_VM_DIR_ENTRIES
];
1099 int m
= kernel_boot_info
.kern_mod
;
1100 #if defined(__i386__)
1101 int global_bit_ok
= 0;
1102 u32_t mypdbr
; /* Page Directory Base Register (cr3) value */
1103 #elif defined(__arm__)
1107 /* Find what the physical location of the kernel is. */
1109 assert(m
< kernel_boot_info
.mods_with_kernel
);
1110 assert(kernel_boot_info
.mods_with_kernel
< MULTIBOOT_MAX_MODS
);
1111 kern_mb_mod
= &kernel_boot_info
.module_list
[m
];
1112 kern_size
= kern_mb_mod
->mod_end
- kern_mb_mod
->mod_start
;
1113 assert(!(kern_mb_mod
->mod_start
% ARCH_BIG_PAGE_SIZE
));
1114 assert(!(kernel_boot_info
.vir_kern_start
% ARCH_BIG_PAGE_SIZE
));
1115 kern_start_pde
= kernel_boot_info
.vir_kern_start
/ ARCH_BIG_PAGE_SIZE
;
1117 /* Get ourselves spare pages. */
1118 sparepages_mem
= (vir_bytes
) static_sparepages
;
1119 assert(!(sparepages_mem
% VM_PAGE_SIZE
));
1121 #if defined(__arm__)
1122 /* Get ourselves spare pagedirs. */
1123 sparepagedirs_mem
= (vir_bytes
) static_sparepagedirs
;
1124 assert(!(sparepagedirs_mem
% ARCH_PAGEDIR_SIZE
));
1127 /* Spare pages are used to allocate memory before VM has its own page
1128 * table that things (i.e. arbitrary physical memory) can be mapped into.
1129 * We get it by pre-allocating it in our bss (allocated and mapped in by
1130 * the kernel) in static_sparepages. We also need the physical addresses
1131 * though; we look them up now so they are ready for use.
1133 #if defined(__arm__)
1134 missing_sparedirs
= 0;
1135 assert(STATIC_SPAREPAGEDIRS
<= SPAREPAGEDIRS
);
1136 for(s
= 0; s
< SPAREPAGEDIRS
; s
++) {
1137 vir_bytes v
= (sparepagedirs_mem
+ s
*ARCH_PAGEDIR_SIZE
);;
1139 if((r
=sys_umap(SELF
, VM_D
, (vir_bytes
) v
,
1140 ARCH_PAGEDIR_SIZE
, &ph
)) != OK
)
1141 panic("pt_init: sys_umap failed: %d", r
);
1142 if(s
>= STATIC_SPAREPAGEDIRS
) {
1143 sparepagedirs
[s
].pagedir
= NULL
;
1144 missing_sparedirs
++;
1147 sparepagedirs
[s
].pagedir
= (void *) v
;
1148 sparepagedirs
[s
].phys
= ph
;
1152 if(!(spare_pagequeue
= reservedqueue_new(SPAREPAGES
, 1, 1, 0)))
1153 panic("reservedqueue_new for single pages failed");
1155 assert(STATIC_SPAREPAGES
< SPAREPAGES
);
1156 for(s
= 0; s
< STATIC_SPAREPAGES
; s
++) {
1157 void *v
= (void *) (sparepages_mem
+ s
*VM_PAGE_SIZE
);
1159 if((r
=sys_umap(SELF
, VM_D
, (vir_bytes
) v
,
1160 VM_PAGE_SIZE
*SPAREPAGES
, &ph
)) != OK
)
1161 panic("pt_init: sys_umap failed: %d", r
);
1162 reservedqueue_add(spare_pagequeue
, v
, ph
);
1165 #if defined(__i386__)
1166 /* global bit and 4MB pages available? */
1167 global_bit_ok
= _cpufeature(_CPUF_I386_PGE
);
1168 bigpage_ok
= _cpufeature(_CPUF_I386_PSE
);
1170 /* Set bit for PTE's and PDE's if available. */
1172 global_bit
= I386_VM_GLOBAL
;
1175 /* Now reserve another pde for kernel's own mappings. */
1178 phys_bytes addr
, len
;
1179 int flags
, pindex
= 0;
1182 kernmap_pde
= freepde();
1183 offset
= kernmap_pde
* ARCH_BIG_PAGE_SIZE
;
1185 while(sys_vmctl_get_mapping(pindex
, &addr
, &len
,
1189 if(pindex
>= MAX_KERNMAPPINGS
)
1190 panic("VM: too many kernel mappings: %d", pindex
);
1191 kern_mappings
[pindex
].phys_addr
= addr
;
1192 kern_mappings
[pindex
].len
= len
;
1193 kern_mappings
[pindex
].flags
= flags
;
1194 kern_mappings
[pindex
].vir_addr
= offset
;
1195 kern_mappings
[pindex
].flags
=
1196 ARCH_VM_PTE_PRESENT
;
1197 if(flags
& VMMF_UNCACHED
)
1198 #if defined(__i386__)
1199 kern_mappings
[pindex
].flags
|= PTF_NOCACHE
;
1200 #elif defined(__arm__)
1201 kern_mappings
[pindex
].flags
|= ARM_VM_PTE_DEVICE
;
1203 kern_mappings
[pindex
].flags
|= ARM_VM_PTE_CACHED
;
1206 if(flags
& VMMF_USER
)
1207 kern_mappings
[pindex
].flags
|= ARCH_VM_PTE_USER
;
1208 #if defined(__arm__)
1210 kern_mappings
[pindex
].flags
|= ARM_VM_PTE_SUPER
;
1212 if(flags
& VMMF_WRITE
)
1213 kern_mappings
[pindex
].flags
|= ARCH_VM_PTE_RW
;
1214 #if defined(__arm__)
1216 kern_mappings
[pindex
].flags
|= ARCH_VM_PTE_RO
;
1219 #if defined(__i386__)
1220 if(flags
& VMMF_GLO
)
1221 kern_mappings
[pindex
].flags
|= I386_VM_GLOBAL
;
1224 if(addr
% VM_PAGE_SIZE
)
1225 panic("VM: addr unaligned: %lu", addr
);
1226 if(len
% VM_PAGE_SIZE
)
1227 panic("VM: len unaligned: %lu", len
);
1229 if(sys_vmctl_reply_mapping(pindex
, vir
) != OK
)
1230 panic("VM: reply failed");
1235 usedpde
= ARCH_VM_PDE(offset
);
1236 while(usedpde
> kernmap_pde
) {
1237 int newpde
= freepde();
1238 assert(newpde
== kernmap_pde
+1);
1239 kernmap_pde
= newpde
;
1244 pt_allocate_kernel_mapped_pagetables();
1246 /* Allright. Now. We have to make our own page directory and page tables,
1247 * that the kernel has already set up, accessible to us. It's easier to
1248 * understand if we just copy all the required pages (i.e. page directory
1249 * and page tables), and set up the pointers as if VM had done it itself.
1251 * This allocation will happen without using any page table, and just
1254 newpt
= &vmprocess
->vm_pt
;
1255 if(pt_new(newpt
) != OK
)
1256 panic("vm pt_new failed");
1258 /* Get our current pagedir so we can see it. */
1259 #if defined(__i386__)
1260 if(sys_vmctl_get_pdbr(SELF
, &mypdbr
) != OK
)
1261 #elif defined(__arm__)
1262 if(sys_vmctl_get_pdbr(SELF
, &myttbr
) != OK
)
1265 panic("VM: sys_vmctl_get_pdbr failed");
1266 #if defined(__i386__)
1267 if(sys_vircopy(NONE
, mypdbr
, SELF
,
1268 (vir_bytes
) currentpagedir
, VM_PAGE_SIZE
, 0) != OK
)
1269 #elif defined(__arm__)
1270 if(sys_vircopy(NONE
, myttbr
, SELF
,
1271 (vir_bytes
) currentpagedir
, ARCH_PAGEDIR_SIZE
, 0) != OK
)
1273 panic("VM: sys_vircopy failed");
1275 /* We have mapped in kernel ourselves; now copy mappings for VM
1276 * that kernel made, including allocations for BSS. Skip identity
1277 * mapping bits; just map in VM.
1279 for(p
= 0; p
< ARCH_VM_DIR_ENTRIES
; p
++) {
1280 u32_t entry
= currentpagedir
[p
];
1281 phys_bytes ptaddr_kern
, ptaddr_us
;
1283 /* BIGPAGEs are kernel mapping (do ourselves) or boot
1284 * identity mapping (don't want).
1286 if(!(entry
& ARCH_VM_PDE_PRESENT
)) continue;
1287 if((entry
& ARCH_VM_BIGPAGE
)) continue;
1289 if(pt_ptalloc(newpt
, p
, 0) != OK
)
1290 panic("pt_ptalloc failed");
1291 assert(newpt
->pt_dir
[p
] & ARCH_VM_PDE_PRESENT
);
1293 #if defined(__i386__)
1294 ptaddr_kern
= entry
& ARCH_VM_ADDR_MASK
;
1295 ptaddr_us
= newpt
->pt_dir
[p
] & ARCH_VM_ADDR_MASK
;
1296 #elif defined(__arm__)
1297 ptaddr_kern
= entry
& ARCH_VM_PDE_MASK
;
1298 ptaddr_us
= newpt
->pt_dir
[p
] & ARCH_VM_PDE_MASK
;
1301 /* Copy kernel-initialized pagetable contents into our
1302 * normally accessible pagetable.
1304 if(sys_abscopy(ptaddr_kern
, ptaddr_us
, VM_PAGE_SIZE
) != OK
)
1305 panic("pt_init: abscopy failed");
1308 /* Inform kernel vm has a newly built page table. */
1309 assert(vmproc
[VM_PROC_NR
].vm_endpoint
== VM_PROC_NR
);
1310 pt_bind(newpt
, &vmproc
[VM_PROC_NR
]);
1314 /* VM is now fully functional in that it can dynamically allocate memory
1317 * We don't want to keep using the bootstrap statically allocated spare
1318 * pages though, as the physical addresses will change on liveupdate. So we
1319 * re-do part of the initialization now with purely dynamically allocated
1320 * memory. First throw out the static pool.
1322 * Then allocate the kernel-shared-pagetables and VM pagetables with dynamic
1326 alloc_cycle(); /* Make sure allocating works */
1327 while(vm_getsparepage(&phys
)) ; /* Use up all static pages */
1328 alloc_cycle(); /* Refill spares with dynamic */
1329 pt_allocate_kernel_mapped_pagetables(); /* Reallocate in-kernel pages */
1330 pt_bind(newpt
, &vmproc
[VM_PROC_NR
]); /* Recalculate */
1331 pt_mapkernel(newpt
); /* Rewrite pagetable info */
1333 /* Flush TLB just in case any of those mappings have been touched */
1334 if((sys_vmctl(SELF
, VMCTL_FLUSHTLB
, 0)) != OK
) {
1335 panic("VMCTL_FLUSHTLB failed");
1338 /* Recreate VM page table with dynamic-only allocations */
1339 memset(&newpt_dyn
, 0, sizeof(newpt_dyn
));
1341 pt_copy(&newpt_dyn
, newpt
);
1342 memcpy(newpt
, &newpt_dyn
, sizeof(*newpt
));
1344 pt_bind(newpt
, &vmproc
[VM_PROC_NR
]); /* Recalculate */
1345 pt_mapkernel(newpt
); /* Rewrite pagetable info */
1347 /* Flush TLB just in case any of those mappings have been touched */
1348 if((sys_vmctl(SELF
, VMCTL_FLUSHTLB
, 0)) != OK
) {
1349 panic("VMCTL_FLUSHTLB failed");
1356 /*===========================================================================*
1358 *===========================================================================*/
1359 int pt_bind(pt_t
*pt
, struct vmproc
*who
)
1361 int procslot
, pdeslot
;
1366 int pages_per_pagedir
= ARCH_PAGEDIR_SIZE
/VM_PAGE_SIZE
;
1369 slots_per_pde
= ARCH_VM_PT_ENTRIES
/ pages_per_pagedir
;
1371 /* Basic sanity checks. */
1373 assert(who
->vm_flags
& VMF_INUSE
);
1376 procslot
= who
->vm_slot
;
1377 pdm
= &pagedir_mappings
[procslot
/slots_per_pde
];
1378 pdeslot
= procslot
%slots_per_pde
;
1379 pagedir_pde
= pdm
->pdeno
;
1380 assert(pdeslot
>= 0);
1381 assert(procslot
< ELEMENTS(vmproc
));
1382 assert(pdeslot
< ARCH_VM_PT_ENTRIES
/ pages_per_pagedir
);
1383 assert(pagedir_pde
>= 0);
1385 #if defined(__i386__)
1386 phys
= pt
->pt_dir_phys
& ARCH_VM_ADDR_MASK
;
1387 #elif defined(__arm__)
1388 phys
= pt
->pt_dir_phys
& ARM_VM_PTE_MASK
;
1390 assert(pt
->pt_dir_phys
== phys
);
1391 assert(!(pt
->pt_dir_phys
% ARCH_PAGEDIR_SIZE
));
1393 /* Update "page directory pagetable." */
1394 #if defined(__i386__)
1395 pdm
->page_directories
[pdeslot
] =
1396 phys
| ARCH_VM_PDE_PRESENT
|ARCH_VM_PTE_RW
;
1397 #elif defined(__arm__)
1400 for (i
= 0; i
< pages_per_pagedir
; i
++) {
1401 pdm
->page_directories
[pdeslot
*pages_per_pagedir
+i
] =
1402 (phys
+i
*VM_PAGE_SIZE
)
1403 | ARCH_VM_PTE_PRESENT
1406 | ARCH_VM_PTE_USER
; //LSC FIXME
1411 /* This is where the PDE's will be visible to the kernel
1412 * in its address space.
1414 pdes
= (void *) (pagedir_pde
*ARCH_BIG_PAGE_SIZE
+
1415 #if defined(__i386__)
1416 pdeslot
* VM_PAGE_SIZE
);
1417 #elif defined(__arm__)
1418 pdeslot
* ARCH_PAGEDIR_SIZE
);
1421 /* Tell kernel about new page table root. */
1422 return sys_vmctl_set_addrspace(who
->vm_endpoint
, pt
->pt_dir_phys
, pdes
);
1425 /*===========================================================================*
1427 *===========================================================================*/
1428 void pt_free(pt_t
*pt
)
1430 /* Free memory associated with this pagetable. */
1433 for(i
= 0; i
< ARCH_VM_DIR_ENTRIES
; i
++)
1435 vm_freepages((vir_bytes
) pt
->pt_pt
[i
], 1);
1440 /*===========================================================================*
1442 *===========================================================================*/
1443 int pt_mapkernel(pt_t
*pt
)
1446 int kern_pde
= kern_start_pde
;
1447 phys_bytes addr
, mapped
= 0;
1449 /* Any page table needs to map in the kernel address space. */
1451 assert(kern_pde
>= 0);
1453 /* pt_init() has made sure this is ok. */
1454 addr
= kern_mb_mod
->mod_start
;
1456 /* Actually mapping in kernel */
1457 while(mapped
< kern_size
) {
1458 #if defined(__i386__)
1459 pt
->pt_dir
[kern_pde
] = addr
| ARCH_VM_PDE_PRESENT
|
1460 ARCH_VM_BIGPAGE
| ARCH_VM_PTE_RW
| global_bit
;
1461 #elif defined(__arm__)
1462 pt
->pt_dir
[kern_pde
] = (addr
& ARM_VM_SECTION_MASK
)
1464 | ARM_VM_SECTION_DOMAIN
1465 | ARM_VM_SECTION_CACHED
1466 | ARM_VM_SECTION_SUPER
;
1469 mapped
+= ARCH_BIG_PAGE_SIZE
;
1470 addr
+= ARCH_BIG_PAGE_SIZE
;
1473 /* Kernel also wants to know about all page directories. */
1476 for(pd
= 0; pd
< MAX_PAGEDIR_PDES
; pd
++) {
1477 struct pdm
*pdm
= &pagedir_mappings
[pd
];
1479 assert(pdm
->pdeno
> 0);
1480 assert(pdm
->pdeno
> kern_pde
);
1481 pt
->pt_dir
[pdm
->pdeno
] = pdm
->val
;
1485 /* Kernel also wants various mappings of its own. */
1486 for(i
= 0; i
< kernmappings
; i
++) {
1488 if((r
=pt_writemap(NULL
, pt
,
1489 kern_mappings
[i
].vir_addr
,
1490 kern_mappings
[i
].phys_addr
,
1491 kern_mappings
[i
].len
,
1492 kern_mappings
[i
].flags
, 0)) != OK
) {
1501 int get_vm_self_pages(void) { return vm_self_pages
; }