The Pedigree Project  0.1
kernel/core/processor/armv7/VirtualAddressSpace.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef KERNEL_PROCESSOR_ARMV7_VIRTUALADDRESSSPACE_H
21 #define KERNEL_PROCESSOR_ARMV7_VIRTUALADDRESSSPACE_H
22 
23 #include "pedigree/kernel/processor/VirtualAddressSpace.h"
24 #include "pedigree/kernel/processor/types.h"
25 
33 #define USERSPACE_DYNAMIC_LINKER_LOCATION reinterpret_cast<void *>(0x1FA00000)
34 #define USERSPACE_VIRTUAL_START reinterpret_cast<void *>(0x1000)
35 #define USERSPACE_VIRTUAL_HEAP reinterpret_cast<void *>(0x20000000)
36 #define USERSPACE_RESERVED_START USERSPACE_DYNAMIC_LINKER_LOCATION
37 #define USERSPACE_VIRTUAL_STACK reinterpret_cast<void *>(0x3FE00000)
38 #define USERSPACE_PAGEDIR \
39  reinterpret_cast<void *>(0x3FFFF000)
40 #define USERSPACE_PAGETABLES reinterpret_cast<void *>(0x3FE00000)
43 #define USERSPACE_VIRTUAL_STACK_SIZE 0x100000
44 #define KERNEL_SPACE_START reinterpret_cast<void *>(0x40000000)
45 #define KERNEL_VIRTUAL_HEAP reinterpret_cast<void *>(0x40000000)
46 #define KERNEL_VIRTUAL_HEAP_SIZE 0x20000000
47 #define KERNEL_VIRTUAL_MODULE_BASE reinterpret_cast<void *>(0x60000000)
48 #define KERNEL_VIRTUAL_MODULE_SIZE 0x400000
49 #define KERNEL_VIRTUAL_ADDRESS reinterpret_cast<void *>(0x80008000)
50 #define KERNEL_VIRTUAL_CACHE reinterpret_cast<void *>(0xA0000000)
51 #define KERNEL_VIRTUAL_CACHE_SIZE 0x10000000
52 #define KERNEL_VIRTUAL_MEMORYREGION_ADDRESS reinterpret_cast<void *>(0xB0000000)
53 #define KERNEL_VIRTUAL_EVENT_BASE reinterpret_cast<void *>(0xE0000000)
54 #define KERNEL_VIRTUAL_PAGESTACK_4GB reinterpret_cast<void *>(0xF0000000)
55 #define KERNEL_VIRTUAL_STACK reinterpret_cast<void *>(0xFEFFF000)
56 #define KERNEL_TEMP0 reinterpret_cast<void *>(0xFE000000)
57 #define KERNEL_TEMP1 reinterpret_cast<void *>(0xFE001000)
58 #define KERNEL_PAGEDIR \
59  reinterpret_cast<void *>(0xFFFB0000) // 0xFFFF0000 is where we'll put the
60  // exception base vectors
61 #define KERNEL_PAGETABLES reinterpret_cast<void *>(0xFF000000)
62 #define KERNEL_VIRTUAL_MEMORYREGION_SIZE 0x30000000
63 #define KERNEL_STACK_SIZE 0x20000
64 
69 {
72  friend class Processor;
75  friend class ArmV7KernelVirtualAddressSpace;
76 
77  public:
78  //
79  // VirtualAddressSpace Interface
80  //
81  virtual bool isAddressValid(void *virtualAddress);
82  virtual bool isMapped(void *virtualAddress);
83 
84  virtual bool
85  map(physical_uintptr_t physicalAddress, void *virtualAddress, size_t flags);
86  virtual void getMapping(
87  void *virtualAddress, physical_uintptr_t &physicalAddress,
88  size_t &flags);
89  virtual void setFlags(void *virtualAddress, size_t newFlags);
90  virtual void unmap(void *virtualAddress);
91  virtual void *allocateStack();
92  virtual void *allocateStack(size_t stackSz);
93  virtual void freeStack(void *pStack);
94 
95  virtual bool memIsInHeap(void *pMem);
96  virtual void *getEndOfHeap();
97 
98  //
99  // Needed for the PhysicalMemoryManager
100  //
110  bool mapPageStructures(
111  physical_uintptr_t physicalAddress, void *virtualAddress, size_t flags);
112 
116  {
117  return 0;
118  };
119 
123  virtual void revertToKernelAddressSpace(){};
124 
126  virtual uintptr_t getKernelStart() const
127  {
128  return reinterpret_cast<uintptr_t>(KERNEL_SPACE_START);
129  }
130 
132  virtual uintptr_t getUserStart() const
133  {
134  return reinterpret_cast<uintptr_t>(USERSPACE_VIRTUAL_START);
135  }
136 
138  virtual uintptr_t getUserReservedStart() const
139  {
140  return reinterpret_cast<uintptr_t>(USERSPACE_RESERVED_START);
141  }
142 
144  virtual uintptr_t getDynamicLinkerAddress() const
145  {
146  return reinterpret_cast<uintptr_t>(USERSPACE_DYNAMIC_LINKER_LOCATION);
147  }
148 
150  virtual uintptr_t getKernelHeapStart() const
151  {
152  return reinterpret_cast<uintptr_t>(KERNEL_VIRTUAL_HEAP);
153  }
154 
156  virtual uintptr_t getKernelHeapEnd() const
157  {
158  return reinterpret_cast<uintptr_t>(KERNEL_VIRTUAL_HEAP) +
159  KERNEL_VIRTUAL_HEAP_SIZE;
160  }
161 
163  virtual uintptr_t getKernelCacheStart() const
164  {
165  return reinterpret_cast<uintptr_t>(KERNEL_VIRTUAL_CACHE);
166  }
167 
169  virtual uintptr_t getKernelCacheEnd() const
170  {
171  return reinterpret_cast<uintptr_t>(KERNEL_VIRTUAL_CACHE) +
172  KERNEL_VIRTUAL_CACHE_SIZE;
173  }
174 
176  virtual uintptr_t getKernelEventBlockStart() const
177  {
178  return reinterpret_cast<uintptr_t>(KERNEL_VIRTUAL_EVENT_BASE);
179  }
180 
182  virtual uintptr_t getKernelModulesStart() const
183  {
184  return reinterpret_cast<uintptr_t>(KERNEL_VIRTUAL_MODULE_BASE);
185  }
186 
188  virtual uintptr_t getKernelModulesEnd() const
189  {
190  return reinterpret_cast<uintptr_t>(KERNEL_VIRTUAL_MODULE_BASE) +
191  KERNEL_VIRTUAL_MODULE_SIZE;
192  }
193 
194  protected:
196  virtual ~ArmV7VirtualAddressSpace();
197 
207  void *Heap, physical_uintptr_t PhysicalPageDirectory,
208  void *VirtualPageDirectory, void *VirtualPageTables,
209  void *VirtualStack);
210 
211  bool doIsMapped(void *virtualAddress);
212  bool doMap(
213  physical_uintptr_t physicalAddress, void *virtualAddress, size_t flags);
214  void doGetMapping(
215  void *virtualAddress, physical_uintptr_t &physicalAddress,
216  size_t &flags);
217  void doSetFlags(void *virtualAddress, size_t newFlags);
218  void doUnmap(void *virtualAddress);
219  void *doAllocateStack(size_t sSize);
220 
221  private:
228  void *Heap, physical_uintptr_t PhysicalPageDirectory,
229  void *VirtualPageDirectory, void *VirtualPageTables);
230 
240 
242  bool initialise();
243 
249  bool getPageTableEntry(void *virtualAddress, uint32_t *&pageTableEntry);
253  uint32_t toFlags(size_t flags);
257  size_t fromFlags(uint32_t Flags);
258 
261  struct FirstLevelDescriptor
264  {
270 
271  union
272  {
273  struct
274  {
275  uint32_t type : 2;
276  uint32_t ignore : 30;
277  } PACKED fault;
278  struct
279  {
280  uint32_t type : 2;
281  uint32_t sbz1 : 1;
282  uint32_t ns : 1;
283  uint32_t sbz2 : 1;
284  uint32_t domain : 4;
285  uint32_t imp : 1;
286  uint32_t baseaddr : 22;
287  } PACKED pageTable;
288  struct
289  {
290  uint32_t type : 2;
291  uint32_t b : 1;
292  uint32_t c : 1;
293  uint32_t xn : 1;
294  uint32_t domain : 4;
295  uint32_t imp : 1;
296  uint32_t ap1 : 2;
297  uint32_t tex : 3;
298  uint32_t ap2 : 1;
299  uint32_t s : 1;
300  uint32_t nG : 1;
301  uint32_t
302  sectiontype : 1;
303  uint32_t ns : 1;
304  uint32_t base : 12;
305  } PACKED section;
306 
307  uint32_t entry;
308  } descriptor;
309  } PACKED;
310 
314  {
319 
320  union
321  {
322  struct
323  {
324  uint32_t type : 2;
325  uint32_t ignore : 30;
326  } PACKED fault;
327  struct
328  {
329  uint32_t type : 2;
330  uint32_t b : 1;
331  uint32_t c : 1;
332  uint32_t ap1 : 2;
333  uint32_t sbz : 3;
334  uint32_t ap2 : 1;
335  uint32_t s : 1;
336  uint32_t nG : 1;
337  uint32_t tex : 3;
338  uint32_t xn : 1;
339  uint32_t base : 16;
340  } PACKED largepage;
341  struct
342  {
343  uint32_t type : 2;
344  uint32_t b : 1;
345  uint32_t c : 1;
346  uint32_t ap1 : 2;
347  uint32_t sbz : 3;
348  uint32_t ap2 : 1;
349  uint32_t s : 1;
350  uint32_t nG : 1;
351  uint32_t base : 20;
352  } PACKED smallpage;
353 
354  uint32_t entry;
355  } descriptor;
356  } PACKED;
357 
359  physical_uintptr_t m_PhysicalPageDirectory;
364 
366  void *m_pStackTop;
369 
372 };
373 
376 {
378  friend class Processor;
384 
385  public:
386  //
387  // VirtualAddressSpace Interface
388  //
389  virtual bool isMapped(void *virtualAddress);
390  virtual bool
391  map(physical_uintptr_t physicalAddress, void *virtualAddress, size_t flags);
392  virtual void getMapping(
393  void *virtualAddress, physical_uintptr_t &physicalAddress,
394  size_t &flags);
395  virtual void setFlags(void *virtualAddress, size_t newFlags);
396  virtual void unmap(void *virtualAddress);
397 
398  virtual bool initialiseKernelAddressSpace();
399 
400  private:
412 
415 };
416 
419 #endif
ArmV7VirtualAddressSpace & operator=(const ArmV7VirtualAddressSpace &)
virtual void unmap(void *virtualAddress)
size_t fromFlags(uint32_t Flags)
bool mapPageStructures(physical_uintptr_t physicalAddress, void *virtualAddress, size_t flags)
virtual void getMapping(void *virtualAddress, physical_uintptr_t &physicalAddress, size_t &flags)
virtual bool memIsInHeap(void *pMem)
static EXPORTED_PUBLIC VirtualAddressSpace & getKernelAddressSpace()
virtual void setFlags(void *virtualAddress, size_t newFlags)
virtual bool isMapped(void *virtualAddress)
static VirtualAddressSpace * create()
uintptr_t physicalAddress(physical_uintptr_t address) PURE
Definition: utils.h:38
bool doMap(physical_uintptr_t physicalAddress, void *virtualAddress, size_t flags)
virtual bool map(physical_uintptr_t physicalAddress, void *virtualAddress, size_t flags)
The exception was caused by a hardware task switch.
Definition: Processor.h:80
bool getPageTableEntry(void *virtualAddress, uint32_t *&pageTableEntry)
union ArmV7VirtualAddressSpace::FirstLevelDescriptor::@88 descriptor
virtual bool isAddressValid(void *virtualAddress)