]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/moe/server/src/dataspace_noncont.h
Update
[l4.git] / l4 / pkg / l4re-core / moe / server / src / dataspace_noncont.h
1 /*
2  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3  *               Alexander Warg <warg@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  *
6  * This file is part of TUD:OS and distributed under the terms of the
7  * GNU General Public License 2.
8  * Please see the COPYING-GPL-2 file for details.
9  */
10 #pragma once
11
12 #include "dataspace.h"
13
14 namespace Moe {
15
16 class Dataspace_noncont : public Dataspace
17 {
18 public:
19   enum
20   {
21     Page_addr_mask = ~((1UL << 12)-1),
22     Page_cow = 0x04UL,
23   };
24
25   class Page
26   {
27   private:
28     unsigned long p;
29
30   public:
31     Page() throw() : p(0) {}
32     void *operator * () const throw() { return (void*)(p & Page_addr_mask); }
33     bool valid() const throw() { return p & Page_addr_mask;}
34     unsigned long flags() const throw() { return p & ~Page_addr_mask; }
35
36     void set(void *addr, unsigned long flags) throw()
37     { p = ((unsigned long)addr & Page_addr_mask) | (flags & ~Page_addr_mask); }
38
39     void flags(unsigned long add, unsigned long del = 0) throw()
40     {
41       p = (p & Page_addr_mask & ~(del & ~Page_addr_mask))
42         | ((unsigned long)add & ~Page_addr_mask);
43     }
44
45     void addr(void *a) throw()
46     { p = (p & ~Page_addr_mask) | ((unsigned long)a & Page_addr_mask); }
47   };
48
49   bool is_static() const throw() { return false; }
50
51   Dataspace_noncont(unsigned long size, unsigned long flags = Writable) throw()
52   : Dataspace(size, flags | Cow_enabled, L4_LOG2_PAGESIZE), pages(0)
53   {}
54
55   virtual ~Dataspace_noncont() {}
56
57   Address address(l4_addr_t offset,
58                   Ds_rw rw = Writable, l4_addr_t hot_spot = 0,
59                   l4_addr_t min = 0, l4_addr_t max = ~0) const;
60   void unmap(bool ro = false) const throw();
61
62   int pre_allocate(l4_addr_t offset, l4_size_t size, unsigned rights);
63
64   virtual Page &page(unsigned long offs) const throw() = 0;
65   virtual Page &alloc_page(unsigned long offs) const = 0;
66
67   unsigned long num_pages() const throw()
68   { return (size()+page_size()-1) / page_size(); }
69
70 #if 0
71 private:
72   unsigned idx_of(unsigned long offset) const { return offset >> 12; }
73
74   void *page(unsigned idx) const
75   { return (void*)(pages[idx] & Page_addr_mask); }
76   unsigned flags(unsigned idx) const { return pages[idx] & ~Page_addr_mask; }
77   void page(unsigned idx, void *page, unsigned flags = 0) const
78   {
79     pages[idx] = (unsigned long)page & Page_addr_mask | flags
80       & ~Page_addr_mask; 
81   }
82 #endif
83
84   void free_page(Page &p) const throw();
85   void unmap_page(Page const &p, bool ro = false) const throw();
86
87 public:
88   long clear(unsigned long offs, unsigned long size) const throw();
89
90   static Dataspace_noncont *create(Q_alloc *q, unsigned long size,
91                                    unsigned long flags = Writable);
92
93 protected:
94   unsigned long *pages;
95
96 };
97 };