home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / kernel-s / v1.2 / linux-1.2 / linux-1 / linux / include / asm-mips / page.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-31  |  8.4 KB  |  235 lines

  1. #ifndef __ASM_MIPS_PAGE_H
  2. #define __ASM_MIPS_PAGE_H
  3.  
  4. #define CONFIG_STRICT_MM_TYPECHECKS
  5.  
  6. #ifndef __ASSEMBLY__
  7.  
  8. #include <linux/linkage.h>
  9.  
  10. #define invalidate()    tlbflush();
  11. extern asmlinkage void tlbflush(void);
  12.  
  13. typedef unsigned short mem_map_t;
  14.  
  15. #ifdef CONFIG_STRICT_MM_TYPECHECKS
  16. /*
  17.  * These are used to make use of C type-checking..
  18.  */
  19. typedef struct { unsigned long pte; } pte_t;
  20. typedef struct { unsigned long pgd; } pgd_t;
  21. typedef struct { unsigned long pgprot; } pgprot_t;
  22.  
  23. #define pte_val(x)    ((x).pte)
  24. #define pgd_val(x)    ((x).pgd)
  25. #define pgprot_val(x)    ((x).pgprot)
  26.  
  27. #define __pte(x)    ((pte_t) { (x) } )
  28. #define __pgd(x)    ((pgd_t) { (x) } )
  29. #define __pgprot(x)    ((pgprot_t) { (x) } )
  30.  
  31. #else /* !defined (CONFIG_STRICT_MM_TYPECHECKS) */
  32. /*
  33.  * .. while these make it easier on the compiler
  34.  */
  35. typedef unsigned long pte_t;
  36. typedef unsigned long pgd_t;
  37. typedef unsigned long pgprot_t;
  38.  
  39. #define pte_val(x)    (x)
  40. #define pgd_val(x)    (x)
  41. #define pgprot_val(x)    (x)
  42.  
  43. #define __pte(x)    (x)
  44. #define __pgd(x)    (x)
  45. #define __pgprot(x)    (x)
  46.  
  47. #endif /* !defined (CONFIG_STRICT_MM_TYPECHECKS) */
  48. #endif /* __ASSEMBLY__ */
  49.  
  50. /*
  51.  * Note that we shift the lower 32bits of each EntryLo[01] entry
  52.  * 6 bits to the left. That way we can convert the PFN into the
  53.  * physical address by a single 'and' operation and gain 6 additional
  54.  * bits for storing information which isn't present in a normal
  55.  * MIPS page table.
  56.  */
  57. #define _PAGE_PRESENT               (1<<0)  /* implemented in software */
  58. #define _PAGE_COW                   (1<<1)  /* implemented in software */
  59. #define _PAGE_DIRTY                 (1<<2)  /* implemented in software */
  60. #define _PAGE_USER                  (1<<3)
  61. #define _PAGE_UNUSED1               (1<<4)
  62. #define _PAGE_UNUSED2               (1<<5)
  63. #define _PAGE_GLOBAL                (1<<6)
  64. #define _PAGE_ACCESSED              (1<<7)   /* The MIPS valid bit      */
  65. #define _PAGE_RW                    (1<<8)   /* The MIPS dirty bit      */
  66. #define _CACHE_CACHABLE_NO_WA       (0<<9)
  67. #define _CACHE_CACHABLE_WA          (1<<9)
  68. #define _CACHE_UNCACHED             (2<<9)
  69. #define _CACHE_CACHABLE_NONCOHERENT (3<<9)
  70. #define _CACHE_CACHABLE_CE          (4<<9)
  71. #define _CACHE_CACHABLE_COW         (5<<9)
  72. #define _CACHE_CACHABLE_CUW         (6<<9)
  73. #define _CACHE_MASK                 (7<<9)
  74.  
  75. #define _PAGE_TABLE     (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED | _PAGE_DIRTY | \
  76.                          _CACHE_CACHABLE_NO_WA)
  77.  
  78. #define _PAGE_CHG_MASK  (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY | _CACHE_MASK)
  79.  
  80. #define PAGE_NONE    __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED)
  81. #define PAGE_SHARED     __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED | _CACHE_CACHABLE_NO_WA)
  82. #define PAGE_COPY       __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | _PAGE_COW | _CACHE_CACHABLE_NO_WA)
  83. #define PAGE_READONLY   __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | _CACHE_CACHABLE_NO_WA)
  84. #define PAGE_KERNEL    __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED)
  85.  
  86. /*
  87.  * MIPS can't do page protection for execute, and considers that the same like
  88.  * read. Also, write permissions imply read permissions. This is the closest
  89.  * we can get by reasonable means..
  90.  */
  91. #define __P000    PAGE_NONE
  92. #define __P001    PAGE_READONLY
  93. #define __P010    PAGE_COPY
  94. #define __P011    PAGE_COPY
  95. #define __P100    PAGE_READONLY
  96. #define __P101    PAGE_READONLY
  97. #define __P110    PAGE_COPY
  98. #define __P111    PAGE_COPY
  99.  
  100. #define __S000    PAGE_NONE
  101. #define __S001    PAGE_READONLY
  102. #define __S010    PAGE_SHARED
  103. #define __S011    PAGE_SHARED
  104. #define __S100    PAGE_READONLY
  105. #define __S101    PAGE_READONLY
  106. #define __S110    PAGE_SHARED
  107. #define __S111    PAGE_SHARED
  108.  
  109. /* PAGE_SHIFT determines the page size */
  110. #define PAGE_SHIFT            12
  111. #define PGDIR_SHIFT            22
  112. #define PAGE_SIZE            (1UL << PAGE_SHIFT)
  113. #define PGDIR_SIZE            (1UL << PGDIR_SHIFT)
  114.  
  115. #ifdef __KERNEL__
  116.  
  117. #define PAGE_OFFSET    KERNELBASE
  118. #define MAP_NR(addr)    (((addr) - PAGE_OFFSET) >> PAGE_SHIFT)
  119. #define MAP_PAGE_RESERVED (1<<15)
  120.  
  121. #if !defined (__ASSEMBLY__)
  122.  
  123. /* page table for 0-4MB for everybody */
  124. extern unsigned long pg0[1024];
  125.  
  126. /*
  127.  * BAD_PAGETABLE is used when we need a bogus page-table, while
  128.  * BAD_PAGE is used for a bogus page.
  129.  *
  130.  * ZERO_PAGE is a global shared page that is always zero: used
  131.  * for zero-mapped memory areas etc..
  132.  */
  133. extern pte_t __bad_page(void);
  134. extern pte_t * __bad_pagetable(void);
  135.  
  136. extern unsigned long __zero_page(void);
  137.  
  138. #define BAD_PAGETABLE __bad_pagetable()
  139. #define BAD_PAGE __bad_page()
  140. #define ZERO_PAGE __zero_page()
  141.  
  142. /* number of bits that fit into a memory pointer */
  143. #define BITS_PER_PTR            (8*sizeof(unsigned long))
  144.  
  145. /* to mask away the intra-page address bits */
  146. #define PAGE_MASK            (~(PAGE_SIZE-1))
  147.  
  148. /* to mask away the intra-page address bits */
  149. #define PGDIR_MASK            (~(PGDIR_SIZE-1))
  150.  
  151. /* to align the pointer to the (next) page boundary */
  152. #define PAGE_ALIGN(addr)        (((addr)+PAGE_SIZE-1)&PAGE_MASK)
  153.  
  154. /* to align the pointer to a pointer address */
  155. #define PTR_MASK            (~(sizeof(void*)-1))
  156.  
  157. /* sizeof(void*)==1<<SIZEOF_PTR_LOG2 */
  158. /* 64-bit machines, beware!  SRB. */
  159. #define SIZEOF_PTR_LOG2            2
  160.  
  161. /* to find an entry in a page-table-directory */
  162. #define PAGE_DIR_OFFSET(tsk,address) \
  163. ((((unsigned long)(address)) >> PGDIR_SHIFT) + (pgd_t *) (tsk)->tss.pg_dir)
  164.  
  165. /* to find an entry in a page-table */
  166. #define PAGE_PTR(address) \
  167. ((unsigned long)(address)>>(PAGE_SHIFT-SIZEOF_PTR_LOG2)&PTR_MASK&~PAGE_MASK)
  168.  
  169. /* the no. of pointers that fit on a page */
  170. #define PTRS_PER_PAGE            (PAGE_SIZE/sizeof(void*))
  171.  
  172. /* to set the page-dir */
  173. #define SET_PAGE_DIR(tsk,pgdir) \
  174. do { \
  175.     (tsk)->tss.pg_dir = (unsigned long) (pgdir); \
  176.     if ((tsk) == current) \
  177.         invalidate(); \
  178. } while (0)
  179.  
  180. extern unsigned long high_memory;
  181.  
  182. extern inline int pte_none(pte_t pte)        { return !pte_val(pte); }
  183. extern inline int pte_present(pte_t pte)    { return pte_val(pte) & _PAGE_PRESENT; }
  184. extern inline void pte_clear(pte_t *ptep)    { pte_val(*ptep) = 0; }
  185.  
  186. extern inline int pgd_none(pgd_t pgd)        { return !pgd_val(pgd); }
  187. extern inline int pgd_bad(pgd_t pgd)        { return (pgd_val(pgd) & ~PAGE_MASK) != _PAGE_TABLE || pgd_val(pgd) > high_memory; }
  188. extern inline int pgd_present(pgd_t pgd)    { return pgd_val(pgd) & _PAGE_PRESENT; }
  189. extern inline void pgd_clear(pgd_t * pgdp)    { pgd_val(*pgdp) = 0; }
  190.  
  191. /*
  192.  * The following only work if pte_present() is true.
  193.  * Undefined behaviour if not..
  194.  */
  195. extern inline int pte_read(pte_t pte)        { return pte_val(pte) & _PAGE_USER; }
  196. extern inline int pte_write(pte_t pte)        { return pte_val(pte) & _PAGE_RW; }
  197. extern inline int pte_exec(pte_t pte)        { return pte_val(pte) & _PAGE_USER; }
  198. extern inline int pte_dirty(pte_t pte)        { return pte_val(pte) & _PAGE_DIRTY; }
  199. extern inline int pte_young(pte_t pte)        { return pte_val(pte) & _PAGE_ACCESSED; }
  200. extern inline int pte_cow(pte_t pte)        { return pte_val(pte) & _PAGE_COW; }
  201.  
  202. extern inline pte_t pte_wrprotect(pte_t pte)    { pte_val(pte) &= ~_PAGE_RW; return pte; }
  203. extern inline pte_t pte_rdprotect(pte_t pte)    { pte_val(pte) &= ~_PAGE_USER; return pte; }
  204. extern inline pte_t pte_exprotect(pte_t pte)    { pte_val(pte) &= ~_PAGE_USER; return pte; }
  205. extern inline pte_t pte_mkclean(pte_t pte)    { pte_val(pte) &= ~_PAGE_DIRTY; return pte; }
  206. extern inline pte_t pte_mkold(pte_t pte)    { pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
  207. extern inline pte_t pte_uncow(pte_t pte)    { pte_val(pte) &= ~_PAGE_COW; return pte; }
  208. extern inline pte_t pte_mkwrite(pte_t pte)    { pte_val(pte) |= _PAGE_RW; return pte; }
  209. extern inline pte_t pte_mkread(pte_t pte)    { pte_val(pte) |= _PAGE_USER; return pte; }
  210. extern inline pte_t pte_mkexec(pte_t pte)    { pte_val(pte) |= _PAGE_USER; return pte; }
  211. extern inline pte_t pte_mkdirty(pte_t pte)    { pte_val(pte) |= _PAGE_DIRTY; return pte; }
  212. extern inline pte_t pte_mkyoung(pte_t pte)    { pte_val(pte) |= _PAGE_ACCESSED; return pte; }
  213. extern inline pte_t pte_mkcow(pte_t pte)    { pte_val(pte) |= _PAGE_COW; return pte; }
  214.  
  215. /*
  216.  * Conversion functions: convert a page and protection to a page entry,
  217.  * and a page entry and page directory to the page they refer to.
  218.  */
  219. extern inline pte_t mk_pte(unsigned long page, pgprot_t pgprot)
  220. { pte_t pte; pte_val(pte) = page | pgprot_val(pgprot); return pte; }
  221.  
  222. extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  223. { pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; }
  224.  
  225. extern inline unsigned long pte_page(pte_t pte)    { return pte_val(pte) & PAGE_MASK; }
  226. extern inline unsigned long pgd_page(pgd_t pgd)    { return pgd_val(pgd) & PAGE_MASK; }
  227.  
  228. extern inline void pgd_set(pgd_t * pgdp, pte_t * ptep)
  229. { pgd_val(*pgdp) = _PAGE_TABLE | (unsigned long) ptep; }
  230.  
  231. #endif /* !defined (__ASSEMBLY__) */
  232. #endif /* defined (__KERNEL__) */
  233.  
  234. #endif /* __ASM_MIPS_PAGE_H */
  235.