]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/vmem_alloc-ia32.cpp
183483c0f8e1b3f615948efddd5187fd0d110a39
[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   Pdir::Iter e = Kmem::kdir->walk(Virt_addr(address), 100,
31                                   pdir_alloc(Kmem_alloc::allocator()));
32   if (EXPECT_FALSE(e.e->valid()))
33     {
34       kdb_ke("page_alloc: address already mapped");
35       goto error;
36     }
37
38   if (e.shift() != Config::PAGE_SHIFT)
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.e = page | Pt_entry::Writable | Pt_entry::Dirty
47     | Pt_entry::Valid | Pt_entry::Referenced | Pt_entry::global();
48   page_map (address, 0, zf, page);
49
50   if (mode & User)
51     e.e->add_attr(Pt_entry::User);
52
53   return address;
54
55 error:
56   Kmem_alloc::allocator()->free(Config::PAGE_SHIFT, vpage); // 2^0 = 1 page
57   return 0;
58 }
59
60
61 //----------------------------------------------------------------------------
62 IMPLEMENTATION[ia32,amd64]:
63
64 IMPLEMENT inline
65 void
66 Vmem_alloc::page_map(void * /*address*/, int /*order*/, Zero_fill /*zf*/,
67                      Address /*phys*/)
68 {}
69