root/include/asm-i386/page.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. pte_none
  2. pte_present
  3. pte_clear
  4. pgd_none
  5. pgd_bad
  6. pgd_present
  7. pgd_clear
  8. pte_read
  9. pte_write
  10. pte_exec
  11. pte_dirty
  12. pte_young
  13. pte_cow
  14. pte_wrprotect
  15. pte_rdprotect
  16. pte_exprotect
  17. pte_mkclean
  18. pte_mkold
  19. pte_uncow
  20. pte_mkwrite
  21. pte_mkread
  22. pte_mkexec
  23. pte_mkdirty
  24. pte_mkyoung
  25. pte_mkcow
  26. mk_pte
  27. pte_modify
  28. pte_page
  29. pgd_page
  30. pgd_set

   1 #ifndef _I386_PAGE_H
   2 #define _I386_PAGE_H
   3 
   4 #define CONFIG_STRICT_MM_TYPECHECKS
   5 
   6 #define invalidate() \
   7 __asm__ __volatile__("movl %%cr3,%%eax\n\tmovl %%eax,%%cr3": : :"ax")
   8 
   9 /* PAGE_SHIFT determines the page size */
  10 #define PAGE_SHIFT                      12
  11 #define PGDIR_SHIFT                     22
  12 #define PAGE_SIZE                       (1UL << PAGE_SHIFT)
  13 #define PGDIR_SIZE                      (1UL << PGDIR_SHIFT)
  14 
  15 #ifdef __KERNEL__
  16 
  17 #define PAGE_OFFSET     0
  18 #define MAP_NR(addr) ((addr) >> PAGE_SHIFT)
  19 #define MAP_PAGE_RESERVED (1<<15)
  20 
  21 typedef unsigned short mem_map_t;
  22 
  23 /* Just any arbitrary offset to the start of the vmalloc VM area: the
  24  * current 8MB value just means that there will be a 8MB "hole" after the
  25  * physical memory until the kernel virtual memory starts.  That means that
  26  * any out-of-bounds memory accesses will hopefully be caught.
  27  * The vmalloc() routines leaves a hole of 4kB between each vmalloced
  28  * area for the same reason. ;)
  29  */
  30 #define VMALLOC_OFFSET  (8*1024*1024)
  31 #define VMALLOC_START ((high_memory + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1))
  32 #define VMALLOC_VMADDR(x) (TASK_SIZE + (unsigned long)(x))
  33 
  34 #ifdef CONFIG_STRICT_MM_TYPECHECKS
  35 /*
  36  * These are used to make use of C type-checking..
  37  */
  38 typedef struct { unsigned long pte; } pte_t;
  39 typedef struct { unsigned long pgd; } pgd_t;
  40 typedef struct { unsigned long pgprot; } pgprot_t;
  41 
  42 #define pte_val(x)      ((x).pte)
  43 #define pgd_val(x)      ((x).pgd)
  44 #define pgprot_val(x)   ((x).pgprot)
  45 
  46 #define __pte(x)        ((pte_t) { (x) } )
  47 #define __pgd(x)        ((pgd_t) { (x) } )
  48 #define __pgprot(x)     ((pgprot_t) { (x) } )
  49 
  50 #else
  51 /*
  52  * .. while these make it easier on the compiler
  53  */
  54 typedef unsigned long pte_t;
  55 typedef unsigned long pgd_t;
  56 typedef unsigned long pgprot_t;
  57 
  58 #define pte_val(x)      (x)
  59 #define pgd_val(x)      (x)
  60 #define pgprot_val(x)   (x)
  61 
  62 #define __pte(x)        (x)
  63 #define __pgd(x)        (x)
  64 #define __pgprot(x)     (x)
  65 
  66 #endif
  67 
  68 #define _PAGE_PRESENT   0x001
  69 #define _PAGE_RW        0x002
  70 #define _PAGE_USER      0x004
  71 #define _PAGE_ACCESSED  0x020
  72 #define _PAGE_DIRTY     0x040
  73 #define _PAGE_COW       0x200   /* implemented in software (one of the AVL bits) */
  74 
  75 #define _PAGE_TABLE     (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED | _PAGE_DIRTY)
  76 #define _PAGE_CHG_MASK  (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
  77 
  78 #define PAGE_NONE       __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED)
  79 #define PAGE_SHARED     __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED)
  80 #define PAGE_COPY       __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | _PAGE_COW)
  81 #define PAGE_READONLY   __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
  82 #define PAGE_KERNEL     __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED)
  83 
  84 /*
  85  * The i386 can't do page protection for execute, and considers that the same are read.
  86  * Also, write permissions imply read permissions. This is the closest we can get..
  87  */
  88 #define __P000  PAGE_NONE
  89 #define __P001  PAGE_READONLY
  90 #define __P010  PAGE_COPY
  91 #define __P011  PAGE_COPY
  92 #define __P100  PAGE_READONLY
  93 #define __P101  PAGE_READONLY
  94 #define __P110  PAGE_COPY
  95 #define __P111  PAGE_COPY
  96 
  97 #define __S000  PAGE_NONE
  98 #define __S001  PAGE_READONLY
  99 #define __S010  PAGE_SHARED
 100 #define __S011  PAGE_SHARED
 101 #define __S100  PAGE_READONLY
 102 #define __S101  PAGE_READONLY
 103 #define __S110  PAGE_SHARED
 104 #define __S111  PAGE_SHARED
 105 
 106 /*
 107  * Define this if things work differently on a i386 and a i486:
 108  * it will (on a i486) warn about kernel memory accesses that are
 109  * done without a 'verify_area(VERIFY_WRITE,..)'
 110  */
 111 #undef CONFIG_TEST_VERIFY_AREA
 112 
 113 /* page table for 0-4MB for everybody */
 114 extern unsigned long pg0[1024];
 115 
 116 /*
 117  * BAD_PAGETABLE is used when we need a bogus page-table, while
 118  * BAD_PAGE is used for a bogus page.
 119  *
 120  * ZERO_PAGE is a global shared page that is always zero: used
 121  * for zero-mapped memory areas etc..
 122  */
 123 extern pte_t __bad_page(void);
 124 extern pte_t * __bad_pagetable(void);
 125 
 126 extern unsigned long __zero_page(void);
 127 
 128 #define BAD_PAGETABLE __bad_pagetable()
 129 #define BAD_PAGE __bad_page()
 130 #define ZERO_PAGE __zero_page()
 131 
 132 /* number of bits that fit into a memory pointer */
 133 #define BITS_PER_PTR                    (8*sizeof(unsigned long))
 134 
 135 /* to mask away the intra-page address bits */
 136 #define PAGE_MASK                       (~(PAGE_SIZE-1))
 137 
 138 /* to mask away the intra-page address bits */
 139 #define PGDIR_MASK                      (~(PGDIR_SIZE-1))
 140 
 141 /* to align the pointer to the (next) page boundary */
 142 #define PAGE_ALIGN(addr)                (((addr)+PAGE_SIZE-1)&PAGE_MASK)
 143 
 144 /* to align the pointer to a pointer address */
 145 #define PTR_MASK                        (~(sizeof(void*)-1))
 146 
 147 /* sizeof(void*)==1<<SIZEOF_PTR_LOG2 */
 148 /* 64-bit machines, beware!  SRB. */
 149 #define SIZEOF_PTR_LOG2                 2
 150 
 151 /* to find an entry in a page-table-directory */
 152 #define PAGE_DIR_OFFSET(tsk,address) \
 153 ((((unsigned long)(address)) >> 22) + (pgd_t *) (tsk)->tss.cr3)
 154 
 155 /* to find an entry in a page-table */
 156 #define PAGE_PTR(address) \
 157 ((unsigned long)(address)>>(PAGE_SHIFT-SIZEOF_PTR_LOG2)&PTR_MASK&~PAGE_MASK)
 158 
 159 /* the no. of pointers that fit on a page */
 160 #define PTRS_PER_PAGE                   (PAGE_SIZE/sizeof(void*))
 161 
 162 /* to set the page-dir */
 163 #define SET_PAGE_DIR(tsk,pgdir) \
 164 do { \
 165         (tsk)->tss.cr3 = (unsigned long) (pgdir); \
 166         if ((tsk) == current) \
 167                 __asm__ __volatile__("movl %0,%%cr3": :"a" ((tsk)->tss.cr3)); \
 168 } while (0)
 169 
 170 extern unsigned long high_memory;
 171 
 172 extern inline int pte_none(pte_t pte)           { return !pte_val(pte); }
     /* [previous][next][first][last][top][bottom][index][help] */
 173 extern inline int pte_present(pte_t pte)        { return pte_val(pte) & _PAGE_PRESENT; }
     /* [previous][next][first][last][top][bottom][index][help] */
 174 extern inline void pte_clear(pte_t *ptep)       { pte_val(*ptep) = 0; }
     /* [previous][next][first][last][top][bottom][index][help] */
 175 
 176 extern inline int pgd_none(pgd_t pgd)           { return !pgd_val(pgd); }
     /* [previous][next][first][last][top][bottom][index][help] */
 177 extern inline int pgd_bad(pgd_t pgd)            { return (pgd_val(pgd) & ~PAGE_MASK) != _PAGE_TABLE || pgd_val(pgd) > high_memory; }
     /* [previous][next][first][last][top][bottom][index][help] */
 178 extern inline int pgd_present(pgd_t pgd)        { return pgd_val(pgd) & _PAGE_PRESENT; }
     /* [previous][next][first][last][top][bottom][index][help] */
 179 extern inline void pgd_clear(pgd_t * pgdp)      { pgd_val(*pgdp) = 0; }
     /* [previous][next][first][last][top][bottom][index][help] */
 180 
 181 /*
 182  * The following only work if pte_present() is true.
 183  * Undefined behaviour if not..
 184  */
 185 extern inline int pte_read(pte_t pte)           { return pte_val(pte) & _PAGE_USER; }
     /* [previous][next][first][last][top][bottom][index][help] */
 186 extern inline int pte_write(pte_t pte)          { return pte_val(pte) & _PAGE_RW; }
     /* [previous][next][first][last][top][bottom][index][help] */
 187 extern inline int pte_exec(pte_t pte)           { return pte_val(pte) & _PAGE_USER; }
     /* [previous][next][first][last][top][bottom][index][help] */
 188 extern inline int pte_dirty(pte_t pte)          { return pte_val(pte) & _PAGE_DIRTY; }
     /* [previous][next][first][last][top][bottom][index][help] */
 189 extern inline int pte_young(pte_t pte)          { return pte_val(pte) & _PAGE_ACCESSED; }
     /* [previous][next][first][last][top][bottom][index][help] */
 190 extern inline int pte_cow(pte_t pte)            { return pte_val(pte) & _PAGE_COW; }
     /* [previous][next][first][last][top][bottom][index][help] */
 191 
 192 extern inline pte_t pte_wrprotect(pte_t pte)    { pte_val(pte) &= ~_PAGE_RW; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 193 extern inline pte_t pte_rdprotect(pte_t pte)    { pte_val(pte) &= ~_PAGE_USER; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 194 extern inline pte_t pte_exprotect(pte_t pte)    { pte_val(pte) &= ~_PAGE_USER; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 195 extern inline pte_t pte_mkclean(pte_t pte)      { pte_val(pte) &= ~_PAGE_DIRTY; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 196 extern inline pte_t pte_mkold(pte_t pte)        { pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 197 extern inline pte_t pte_uncow(pte_t pte)        { pte_val(pte) &= ~_PAGE_COW; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 198 extern inline pte_t pte_mkwrite(pte_t pte)      { pte_val(pte) |= _PAGE_RW; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 199 extern inline pte_t pte_mkread(pte_t pte)       { pte_val(pte) |= _PAGE_USER; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 200 extern inline pte_t pte_mkexec(pte_t pte)       { pte_val(pte) |= _PAGE_USER; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 201 extern inline pte_t pte_mkdirty(pte_t pte)      { pte_val(pte) |= _PAGE_DIRTY; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 202 extern inline pte_t pte_mkyoung(pte_t pte)      { pte_val(pte) |= _PAGE_ACCESSED; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 203 extern inline pte_t pte_mkcow(pte_t pte)        { pte_val(pte) |= _PAGE_COW; return pte; }
     /* [previous][next][first][last][top][bottom][index][help] */
 204 
 205 /*
 206  * Conversion functions: convert a page and protection to a page entry,
 207  * and a page entry and page directory to the page they refer to.
 208  */
 209 extern inline pte_t mk_pte(unsigned long page, pgprot_t pgprot)
     /* [previous][next][first][last][top][bottom][index][help] */
 210 { pte_t pte; pte_val(pte) = page | pgprot_val(pgprot); return pte; }
 211 
 212 extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
     /* [previous][next][first][last][top][bottom][index][help] */
 213 { pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; }
 214 
 215 extern inline unsigned long pte_page(pte_t pte) { return pte_val(pte) & PAGE_MASK; }
     /* [previous][next][first][last][top][bottom][index][help] */
 216 extern inline unsigned long pgd_page(pgd_t pgd) { return pgd_val(pgd) & PAGE_MASK; }
     /* [previous][next][first][last][top][bottom][index][help] */
 217 
 218 extern inline void pgd_set(pgd_t * pgdp, pte_t * ptep)
     /* [previous][next][first][last][top][bottom][index][help] */
 219 { pgd_val(*pgdp) = _PAGE_TABLE | (unsigned long) ptep; }
 220 
 221 #endif /* __KERNEL__ */
 222 
 223 #endif /* _I386_PAGE_H */

/* [previous][next][first][last][top][bottom][index][help] */