1 #ifndef _I386_PAGE_H
2 #define _I386_PAGE_H
3
4 #define invalidate() \
5 __asm__ __volatile__("movl %%cr3,%%eax\n\tmovl %%eax,%%cr3": : :"ax")
6
7
8 #define PAGE_SHIFT 12
9 #define PGDIR_SHIFT 22
10 #define PAGE_SIZE (1UL << PAGE_SHIFT)
11 #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
12
13 #define PAGE_OFFSET 0
14 #define MAP_NR(addr) ((addr) >> PAGE_SHIFT)
15 #define MAP_PAGE_RESERVED (1<<15)
16
17 typedef unsigned short mem_map_t;
18
19 #define PAGE_PRESENT 0x001
20 #define PAGE_RW 0x002
21 #define PAGE_USER 0x004
22 #define PAGE_PWT 0x008
23 #define PAGE_PCD 0x010
24 #define PAGE_ACCESSED 0x020
25 #define PAGE_DIRTY 0x040
26 #define PAGE_COW 0x200
27
28 #define PAGE_PRIVATE (PAGE_PRESENT | PAGE_RW | PAGE_USER | PAGE_ACCESSED | PAGE_COW)
29 #define PAGE_SHARED (PAGE_PRESENT | PAGE_RW | PAGE_USER | PAGE_ACCESSED)
30 #define PAGE_COPY (PAGE_PRESENT | PAGE_USER | PAGE_ACCESSED | PAGE_COW)
31 #define PAGE_READONLY (PAGE_PRESENT | PAGE_USER | PAGE_ACCESSED)
32 #define PAGE_EXECONLY (PAGE_PRESENT | PAGE_USER | PAGE_ACCESSED)
33 #define PAGE_TABLE (PAGE_PRESENT | PAGE_RW | PAGE_USER | PAGE_ACCESSED)
34
35 #define PAGE_CHG_MASK (PAGE_MASK | PAGE_ACCESSED | PAGE_DIRTY | PAGE_PWT | PAGE_PCD)
36
37 #ifdef __KERNEL__
38
39
40
41
42
43
44 #undef CONFIG_TEST_VERIFY_AREA
45
46
47 extern unsigned long pg0[1024];
48
49
50
51
52
53
54
55
56 extern unsigned long __bad_page(void);
57 extern unsigned long __bad_pagetable(void);
58 extern unsigned long __zero_page(void);
59
60 #define BAD_PAGETABLE __bad_pagetable()
61 #define BAD_PAGE __bad_page()
62 #define ZERO_PAGE __zero_page()
63
64
65 #define BITS_PER_PTR (8*sizeof(unsigned long))
66
67
68 #define PAGE_MASK (~(PAGE_SIZE-1))
69
70
71 #define PGDIR_MASK (~(PGDIR_SIZE-1))
72
73
74 #define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
75
76
77 #define PTR_MASK (~(sizeof(void*)-1))
78
79
80
81 #define SIZEOF_PTR_LOG2 2
82
83
84 #define PAGE_DIR_OFFSET(tsk,address) \
85 ((((unsigned long)(address)) >> 22) + (unsigned long *) (tsk)->tss.cr3)
86
87
88 #define PAGE_PTR(address) \
89 ((unsigned long)(address)>>(PAGE_SHIFT-SIZEOF_PTR_LOG2)&PTR_MASK&~PAGE_MASK)
90
91
92 #define PTRS_PER_PAGE (PAGE_SIZE/sizeof(void*))
93
94
95 #define SET_PAGE_DIR(tsk,pgdir) \
96 do { \
97 (tsk)->tss.cr3 = (unsigned long) (pgdir); \
98 if ((tsk) == current) \
99 __asm__ __volatile__("movl %0,%%cr3": :"a" ((tsk)->tss.cr3)); \
100 } while (0)
101
102 #endif
103
104 #endif