]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/arm/vmem_alloc-arch.cpp
update
[l4.git] / kernel / fiasco / src / kern / arm / vmem_alloc-arch.cpp
1 //---------------------------------------------------------------------------
2 IMPLEMENTATION [arm]:
3
4 #include "mem.h"
5 #include "paging.h"
6 #include "mem_space.h"
7 #include "kmem_alloc.h"
8 #include "config.h"
9 #include "panic.h"
10 #include "kdb_ke.h"
11 #include "mem_unit.h"
12 #include "ram_quota.h"
13 #include "static_init.h"
14
15 #include <cstdio>
16 #include <cassert>
17 #include <cstring>
18
19
20 IMPLEMENT
21 void *Vmem_alloc::page_alloc(void *address, Zero_fill zf, unsigned mode)
22 {
23   void *vpage = Kmem_alloc::allocator()->alloc(Config::PAGE_SHIFT);
24
25   if (EXPECT_FALSE(!vpage))
26     return 0;
27
28   Address page = Mem_space::kernel_space()->virt_to_phys((Address)vpage);
29   //printf("  allocated page (virt=%p, phys=%08lx\n", vpage, page);
30   Mem_unit::inv_dcache(vpage, ((char*)vpage) + Config::PAGE_SIZE);
31
32   // insert page into master page table
33   auto pte = Mem_space::kernel_space()->dir()->walk(Virt_addr(address),
34       Pdir::Depth, true, Kmem_alloc::q_allocator(Ram_quota::root));
35
36   Page::Rights r = Page::Rights::RWX();
37   if (mode & User)
38     r |= Page::Rights::U();
39
40   pte.create_page(Phys_mem_addr(page), Page::Attr(r, Page::Type::Normal(), Page::Kern::Global()));
41   pte.write_back_if(true, Mem_unit::Asid_kernel);
42   Mem_unit::dtlb_flush(address);
43
44   if (zf == ZERO_FILL)
45     Mem::memset_mwords((unsigned long *)address, 0, Config::PAGE_SIZE >> 2);
46
47   return address;
48 }
49