summaryrefslogtreecommitdiffstats
path: root/src/include/kernel/spte.H
blob: 49c15f83ce43406b2e7ef97d4806a0df8e4de68e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//  IBM_PROLOG_BEGIN_TAG
//  This is an automatically generated prolog.
//
//  $Source: src/include/kernel/spte.H $
//
//  IBM CONFIDENTIAL
//
//  COPYRIGHT International Business Machines Corp. 2011
//
//  p1
//
//  Object Code Only (OCO) source materials
//  Licensed Internal Code Source Materials
//  IBM HostBoot Licensed Internal Code
//
//  The source code for this program is not published or other-
//  wise divested of its trade secrets, irrespective of what has
//  been deposited with the U.S. Copyright Office.
//
//  Origin: 30
//
//  IBM_PROLOG_END
/** @file spte.H
 *  @brief Defines the structure of the Shadow Page Table Entry.
 */
#ifndef __KERNEL_SPTE_H
#define __KERNEL_SPTE_H

#include <stdint.h>
#include <builtins.h>

/** @class ShadowPTE
 *  @brief Stores information needed in a shadow page table for virtual to
 *         physical address mapping, such as physical page number and
 *         security permissions.
 *
 *  @note This structure only allows addressing of 4GB of physical memory due
 *        to the page number being stored in a 20 bit field.
 *
 *  The data within is stored in a way so that the union value is an address
 *  within the physical page who's number is stored and the low-order bits
 *  are used for storing misc information about the page, such as permissions.
 */
class ShadowPTE
{
    protected:
        union
        {
            uint32_t word;
            struct
            {
                    /** Physical page number. */
                uint32_t page:20;
                    /** Page is present (is PN valid?). */
                uint32_t present:1;
                    /** May the page be read        */
		uint32_t readable:1;
                    /** May the page be written to. */
                uint32_t writable:1;
                    /** May code be executed off page. */
                uint32_t executable:1;

                    /** Should the dirty bit be maintained. */
                uint32_t track_write:1;
                    /** Has page been written to. */
                uint32_t dirty:1;
                    /** Allocate from a zero'd page. */
                uint32_t allocate_from_zero:1;
                    /** LRU value - lower means it was accessed more recently. */
                uint32_t last_access:3;
                    /** Reserved for future use. */
                uint32_t reserved:2;
            } PACKED;
        };

    public:
            /** Initialize PTE */
        ShadowPTE() : word(0) {};
            /** Cast-construct from integer directly to the data union. */
        explicit ShadowPTE(uint32_t i_data) : word(i_data) {};

            /** Get physical page (as address). */
        uint32_t getPageAddr() const { return (page << 12); };
            /** Set physical page (as address). */
        void setPageAddr(uint32_t i_page) { page = (i_page >> 12); };
            /** Get physical page (as page number). */
        uint32_t getPage() const { return page; }

            /** Get present bit. */
        bool isPresent() const { return present; };
            /** Set present bit. */
        void setPresent(bool i_present) { present = i_present; };
            /** Get readable bit. */
        bool isReadable() const { return readable; };
            /** Set readable bit. */
        void setReadable(bool i_read) { readable = i_read; };
            /** Get writable bit. */
        bool isWritable() const { return writable; };
            /** Set writable bit. */
        void setWritable(bool i_write) { writable = i_write; };
            /** Get executable bit. */
        bool isExecutable() const { return executable; };
            /** Set executable bit. */
        void setExecutable(bool i_exec) { executable = i_exec; };

            /** Get write-tracked bit. */
        bool isWriteTracked() const { return track_write; };
            /** Set write-tracked bit. */
        void setWriteTracked(bool i_track) { track_write = i_track; };
            /** Get dirty bit. */
        bool isDirty() const { return dirty; };
            /** Set dirty bit. */
        void setDirty(bool i_dirty) { dirty = i_dirty; };

            /** Get allocate-from-zero bit. */
        bool isAllocateFromZero() const { return allocate_from_zero; };
            /** Set allocate-from-zero bit. */
        void setAllocateFromZero(bool i_zero) { allocate_from_zero = i_zero; };

            /** Get last_acces bits. */
        uint8_t getLRU() const { return last_access; };
            /** Increment the LRU bits. */
        void incLRU() {
	    if( last_access < 0b111 )
	    {
		last_access++;
	    }
	};
            /** Decrement the LRU bits. */
        void decLRU() {
	    if( last_access > 0 )
	    {
		last_access--;
	    }
	};
            /** Zero out the LRU bits. */
        void zeroLRU() {
	    last_access = 0;
	};


};

#endif
OpenPOWER on IntegriCloud