source: mainline/kernel/arch/abs32le/include/mm/page.h@ fa8f1f7

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since fa8f1f7 was dc0b964, checked in by Martin Decky <martin@…>, 15 years ago
  • do not hardwire PRI??? formatting macros in the sources, use autotool to detect the correct values
  • use autotool to detect correct values for integer literal macros (UINT32_C, etc.)
  • start using portable UINT??_C style macros for integer constants
  • Property mode set to 100644
File size: 5.8 KB
Line 
1/*
2 * Copyright (c) 2010 Martin Decky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup abs32lemm
30 * @{
31 */
32/** @file
33 */
34
35#ifndef KERN_abs32le_PAGE_H_
36#define KERN_abs32le_PAGE_H_
37
38#include <arch/mm/frame.h>
39#include <trace.h>
40
41#define PAGE_WIDTH FRAME_WIDTH
42#define PAGE_SIZE FRAME_SIZE
43
44#ifdef KERNEL
45
46#define KA2PA(x) (((uintptr_t) (x)) - UINT32_C(0x80000000))
47#define PA2KA(x) (((uintptr_t) (x)) + UINT32_C(0x80000000))
48
49/*
50 * This is an example of 2-level page tables (PTL1 and PTL2 are left out)
51 * on top of the generic 4-level page table interface.
52 */
53
54/* Number of entries in each level. */
55#define PTL0_ENTRIES_ARCH 1024
56#define PTL1_ENTRIES_ARCH 0
57#define PTL2_ENTRIES_ARCH 0
58#define PTL3_ENTRIES_ARCH 1024
59
60/* Page table sizes for each level. */
61#define PTL0_SIZE_ARCH ONE_FRAME
62#define PTL1_SIZE_ARCH 0
63#define PTL2_SIZE_ARCH 0
64#define PTL3_SIZE_ARCH ONE_FRAME
65
66/* Macros calculating indices for each level. */
67#define PTL0_INDEX_ARCH(vaddr) (((vaddr) >> 22) & 0x3ffU)
68#define PTL1_INDEX_ARCH(vaddr) 0
69#define PTL2_INDEX_ARCH(vaddr) 0
70#define PTL3_INDEX_ARCH(vaddr) (((vaddr) >> 12) & 0x3ffU)
71
72/* Get PTE address accessors for each level. */
73#define GET_PTL1_ADDRESS_ARCH(ptl0, i) \
74 ((pte_t *) ((((pte_t *) (ptl0))[(i)].frame_address) << 12))
75#define GET_PTL2_ADDRESS_ARCH(ptl1, i) \
76 (ptl1)
77#define GET_PTL3_ADDRESS_ARCH(ptl2, i) \
78 (ptl2)
79#define GET_FRAME_ADDRESS_ARCH(ptl3, i) \
80 ((uintptr_t) ((((pte_t *) (ptl3))[(i)].frame_address) << 12))
81
82/* Set PTE address accessors for each level. */
83#define SET_PTL0_ADDRESS_ARCH(ptl0)
84#define SET_PTL1_ADDRESS_ARCH(ptl0, i, a) \
85 (((pte_t *) (ptl0))[(i)].frame_address = (a) >> 12)
86#define SET_PTL2_ADDRESS_ARCH(ptl1, i, a)
87#define SET_PTL3_ADDRESS_ARCH(ptl2, i, a)
88#define SET_FRAME_ADDRESS_ARCH(ptl3, i, a) \
89 (((pte_t *) (ptl3))[(i)].frame_address = (a) >> 12)
90
91/* Get PTE flags accessors for each level. */
92#define GET_PTL1_FLAGS_ARCH(ptl0, i) \
93 get_pt_flags((pte_t *) (ptl0), (size_t) (i))
94#define GET_PTL2_FLAGS_ARCH(ptl1, i) \
95 PAGE_PRESENT
96#define GET_PTL3_FLAGS_ARCH(ptl2, i) \
97 PAGE_PRESENT
98#define GET_FRAME_FLAGS_ARCH(ptl3, i) \
99 get_pt_flags((pte_t *) (ptl3), (size_t) (i))
100
101/* Set PTE flags accessors for each level. */
102#define SET_PTL1_FLAGS_ARCH(ptl0, i, x) \
103 set_pt_flags((pte_t *) (ptl0), (size_t) (i), (x))
104#define SET_PTL2_FLAGS_ARCH(ptl1, i, x)
105#define SET_PTL3_FLAGS_ARCH(ptl2, i, x)
106#define SET_FRAME_FLAGS_ARCH(ptl3, i, x) \
107 set_pt_flags((pte_t *) (ptl3), (size_t) (i), (x))
108
109/* Macros for querying the last level entries. */
110#define PTE_VALID_ARCH(p) \
111 (*((uint32_t *) (p)) != 0)
112#define PTE_PRESENT_ARCH(p) \
113 ((p)->present != 0)
114#define PTE_GET_FRAME_ARCH(p) \
115 ((p)->frame_address << FRAME_WIDTH)
116#define PTE_WRITABLE_ARCH(p) \
117 ((p)->writeable != 0)
118#define PTE_EXECUTABLE_ARCH(p) 1
119
120#include <mm/mm.h>
121#include <arch/interrupt.h>
122#include <typedefs.h>
123
124/** Page Table Entry. */
125typedef struct {
126 unsigned int present : 1;
127 unsigned int writeable : 1;
128 unsigned int uaccessible : 1;
129 unsigned int page_write_through : 1;
130 unsigned int page_cache_disable : 1;
131 unsigned int accessed : 1;
132 unsigned int dirty : 1;
133 unsigned int pat : 1;
134 unsigned int global : 1;
135
136 /** Valid content even if the present bit is not set. */
137 unsigned int soft_valid : 1;
138 unsigned int avl : 2;
139 unsigned int frame_address : 20;
140} __attribute__((packed)) pte_t;
141
142NO_TRACE static inline unsigned int get_pt_flags(pte_t *pt, size_t i)
143 REQUIRES_ARRAY_MUTABLE(pt, PTL0_ENTRIES_ARCH)
144{
145 pte_t *p = &pt[i];
146
147 return (
148 ((unsigned int) (!p->page_cache_disable) << PAGE_CACHEABLE_SHIFT) |
149 ((unsigned int) (!p->present) << PAGE_PRESENT_SHIFT) |
150 ((unsigned int) p->uaccessible << PAGE_USER_SHIFT) |
151 (1 << PAGE_READ_SHIFT) |
152 ((unsigned int) p->writeable << PAGE_WRITE_SHIFT) |
153 (1 << PAGE_EXEC_SHIFT) |
154 ((unsigned int) p->global << PAGE_GLOBAL_SHIFT)
155 );
156}
157
158NO_TRACE static inline void set_pt_flags(pte_t *pt, size_t i, int flags)
159 WRITES(ARRAY_RANGE(pt, PTL0_ENTRIES_ARCH))
160 REQUIRES_ARRAY_MUTABLE(pt, PTL0_ENTRIES_ARCH)
161{
162 pte_t *p = &pt[i];
163
164 p->page_cache_disable = !(flags & PAGE_CACHEABLE);
165 p->present = !(flags & PAGE_NOT_PRESENT);
166 p->uaccessible = (flags & PAGE_USER) != 0;
167 p->writeable = (flags & PAGE_WRITE) != 0;
168 p->global = (flags & PAGE_GLOBAL) != 0;
169
170 /*
171 * Ensure that there is at least one bit set even if the present bit is
172 * cleared.
173 */
174 p->soft_valid = true;
175}
176
177extern void page_arch_init(void);
178extern void page_fault(unsigned int, istate_t *);
179
180#endif /* KERNEL */
181
182#endif
183
184/** @}
185 */
Note: See TracBrowser for help on using the repository browser.