]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/vmem_alloc-ia32.cpp
update
[l4.git] / kernel / fiasco / src / kern / ia32 / vmem_alloc-ia32.cpp
1 IMPLEMENTATION[ia32,ux,amd64]:
2
3 #include <cassert>
4 #include <cstdio>
5 #include <cstring>
6 #include "config.h"
7 #include "kdb_ke.h"
8 #include "kmem.h"
9 #include "kmem_alloc.h"
10 #include "mem_layout.h"
11 #include "mem_unit.h"
12 #include "paging.h"
13 #include "static_init.h"
14 #include "initcalls.h"
15 #include "space.h"
16
17 IMPLEMENT
18 void*
19 Vmem_alloc::page_alloc(void *address, Zero_fill zf, unsigned mode)
20 {
21   void *vpage = 0;
22   Address page;
23
24   vpage = Kmem_alloc::allocator()->alloc(Config::PAGE_SHIFT);
25
26   if (EXPECT_FALSE(!vpage))
27     return 0;
28
29   // insert page into master page table
30   auto e = Kmem::kdir->walk(Virt_addr(address), Pdir::Depth,
31                             false, pdir_alloc(Kmem_alloc::allocator()));
32   if (EXPECT_FALSE(e.is_valid()))
33     {
34       kdb_ke("page_alloc: address already mapped");
35       goto error;
36     }
37
38   if (e.level != Pdir::Depth)
39     goto error;
40
41   if (zf == ZERO_FILL)
42     memset(vpage, 0, Config::PAGE_SIZE);
43
44   page = Mem_layout::pmem_to_phys((Address)vpage);
45
46   e.set_page(page, Pt_entry::Writable | Pt_entry::Dirty
47                    | Pt_entry::Referenced
48                    | Pt_entry::global() | (mode & User ? (unsigned)Pt_entry::User : 0));
49   page_map (address, 0, zf, page);
50   return address;
51
52 error:
53   Kmem_alloc::allocator()->free(Config::PAGE_SHIFT, vpage); // 2^0 = 1 page
54   return 0;
55 }
56
57
58 //----------------------------------------------------------------------------
59 IMPLEMENTATION[ia32,amd64]:
60
61 IMPLEMENT inline
62 void
63 Vmem_alloc::page_map(void * /*address*/, int /*order*/, Zero_fill /*zf*/,
64                      Address /*phys*/)
65 {}
66