The Pedigree Project  0.1
HashedPageTable.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_PPC32_HASHEDPAGETABLE_H
21 #define KERNEL_PROCESSOR_PPC32_HASHEDPAGETABLE_H
22 
23 #include "Translation.h"
24 #include "pedigree/kernel/processor/types.h"
25 
26 #define HTAB_VIRTUAL 0xC0100000
27 
37 {
38  public:
40  ~HashedPageTable();
41 
43  static HashedPageTable &instance();
44 
46  void initialise(Translations &translations, uint32_t ramMax);
47 
54  void addMapping(
55  uint32_t effectiveAddress, uint32_t physicalAddress, uint32_t mode,
56  uint32_t vsid);
57 
59  void removeMapping(uint32_t effectiveAddress, uint32_t vsid);
60 
63  bool isMapped(uint32_t effectiveAddress, uint32_t vsid);
64 
67  uint32_t getMapping(uint32_t effectiveAddress, uint32_t vsid);
68 
69  private:
71  HashedPageTable &operator=(const HashedPageTable &);
72 
74  struct PTE
75  {
76  uint32_t v : 1; // Entry valid?
77  uint32_t vsid : 24; // Virtual segment ID
78  uint32_t h : 1; // Hash function identifier
79  uint32_t api : 6; // Abbreviated page index.
80  uint32_t rpn : 20; // Physical page number.
81  uint32_t reserved1 : 3;
82  uint32_t r : 1; // Reference bit.
83  uint32_t c : 1; // Change bit.
84  uint32_t w : 1; // Memory/cache control bits.
85  uint32_t i : 1;
86  uint32_t m : 1;
87  uint32_t g : 1;
88  uint32_t reserved2 : 1;
89  uint32_t pp : 2; // Page protection bits.
90  };
92  struct BATU
93  {
94  uint32_t bepi : 15; // Effective page index.
95  uint32_t unused : 4;
96  uint32_t bl : 11; // Block size mask.
97  uint32_t vs : 1; // Supervisor valid.
98  uint32_t vp : 1; // User valid.
99  };
101  struct BATL
102  {
103  uint32_t brpn : 15; // Real page index.
104  uint32_t unused1 : 10;
105  uint32_t wimg : 4; // Memory/cache control bits.
106  uint32_t unused2 : 1;
107  uint32_t pp : 2; // Page access protections.
108  };
109 
111  struct PTEG
112  {
113  PTE entries[8];
114  };
115 
117  void setIBAT(
118  size_t n, uintptr_t virt, physical_uintptr_t phys, size_t size,
119  uint32_t mode);
121  void setDBAT(
122  size_t n, uintptr_t virt, physical_uintptr_t phys, size_t size,
123  uint32_t mode);
124 
127 
129  uint32_t m_Size;
130 
132  uint32_t m_Mask;
133 
136 };
137 
138 #endif
static HashedPageTable & instance()
void setDBAT(size_t n, uintptr_t virt, physical_uintptr_t phys, size_t size, uint32_t mode)
void setIBAT(size_t n, uintptr_t virt, physical_uintptr_t phys, size_t size, uint32_t mode)
bool isMapped(uint32_t effectiveAddress, uint32_t vsid)
void addMapping(uint32_t effectiveAddress, uint32_t physicalAddress, uint32_t mode, uint32_t vsid)
void removeMapping(uint32_t effectiveAddress, uint32_t vsid)
static HashedPageTable m_Instance
uint32_t getMapping(uint32_t effectiveAddress, uint32_t vsid)
uintptr_t physicalAddress(physical_uintptr_t address) PURE
Definition: utils.h:38
void initialise(Translations &translations, uint32_t ramMax)