page.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003-2004 Jakub Jermar
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #ifndef __mips32_PAGE_H__
00036 #define __mips32_PAGE_H__
00037 
00038 #include <arch/mm/frame.h>
00039 
00040 #define PAGE_WIDTH      FRAME_WIDTH
00041 #define PAGE_SIZE       FRAME_SIZE
00042 
00043 #ifndef __ASM__
00044 #  define KA2PA(x)      (((__address) (x)) - 0x80000000)
00045 #  define PA2KA(x)      (((__address) (x)) + 0x80000000)
00046 #else
00047 #  define KA2PA(x)      ((x) - 0x80000000)
00048 #  define PA2KA(x)      ((x) + 0x80000000)
00049 #endif
00050 
00051 #ifdef KERNEL
00052 
00053 /*
00054  * Implementation of generic 4-level page table interface.
00055  * NOTE: this implementation is under construction
00056  * 
00057  * Page table layout:
00058  * - 32-bit virtual addresses
00059  * - Offset is 14 bits => pages are 16K long
00060  * - PTE's use similar format as CP0 EntryLo[01] registers => PTE is therefore 4 bytes long
00061  * - PTE's replace EntryLo v (valid) bit with p (present) bit
00062  * - PTE's use only one bit to distinguish between cacheable and uncacheable mappings
00063  * - PTE's define soft_valid field to ensure there is at least one 1 bit even if the p bit is cleared
00064  * - PTE's make use of CP0 EntryLo's two-bit reserved field for bit W (writable) and bit A (accessed)
00065  * - PTL0 has 64 entries (6 bits)
00066  * - PTL1 is not used
00067  * - PTL2 is not used
00068  * - PTL3 has 4096 entries (12 bits)
00069  */
00070  
00071 #define PTL0_ENTRIES_ARCH       64
00072 #define PTL1_ENTRIES_ARCH       0
00073 #define PTL2_ENTRIES_ARCH       0
00074 #define PTL3_ENTRIES_ARCH       4096
00075 
00076 #define PTL0_INDEX_ARCH(vaddr)  ((vaddr)>>26) 
00077 #define PTL1_INDEX_ARCH(vaddr)  0
00078 #define PTL2_INDEX_ARCH(vaddr)  0
00079 #define PTL3_INDEX_ARCH(vaddr)  (((vaddr)>>14) & 0xfff)
00080 
00081 #define SET_PTL0_ADDRESS_ARCH(ptl0)
00082 
00083 #define GET_PTL1_ADDRESS_ARCH(ptl0, i)          (((pte_t *)(ptl0))[(i)].pfn<<12)
00084 #define GET_PTL2_ADDRESS_ARCH(ptl1, i)          (ptl1)
00085 #define GET_PTL3_ADDRESS_ARCH(ptl2, i)          (ptl2)
00086 #define GET_FRAME_ADDRESS_ARCH(ptl3, i)         (((pte_t *)(ptl3))[(i)].pfn<<12)
00087 
00088 #define SET_PTL1_ADDRESS_ARCH(ptl0, i, a)       (((pte_t *)(ptl0))[(i)].pfn = (a)>>12)
00089 #define SET_PTL2_ADDRESS_ARCH(ptl1, i, a)
00090 #define SET_PTL3_ADDRESS_ARCH(ptl2, i, a)
00091 #define SET_FRAME_ADDRESS_ARCH(ptl3, i, a)      (((pte_t *)(ptl3))[(i)].pfn = (a)>>12)
00092 
00093 #define GET_PTL1_FLAGS_ARCH(ptl0, i)            get_pt_flags((pte_t *)(ptl0), (index_t)(i))
00094 #define GET_PTL2_FLAGS_ARCH(ptl1, i)            PAGE_PRESENT
00095 #define GET_PTL3_FLAGS_ARCH(ptl2, i)            PAGE_PRESENT
00096 #define GET_FRAME_FLAGS_ARCH(ptl3, i)           get_pt_flags((pte_t *)(ptl3), (index_t)(i))
00097 
00098 #define SET_PTL1_FLAGS_ARCH(ptl0, i, x)         set_pt_flags((pte_t *)(ptl0), (index_t)(i), (x))
00099 #define SET_PTL2_FLAGS_ARCH(ptl1, i, x)
00100 #define SET_PTL3_FLAGS_ARCH(ptl2, i, x)
00101 #define SET_FRAME_FLAGS_ARCH(ptl3, i, x)        set_pt_flags((pte_t *)(ptl3), (index_t)(i), (x))
00102 
00103 #define PTE_VALID_ARCH(pte)                     (*((__u32 *) (pte)) != 0)
00104 #define PTE_PRESENT_ARCH(pte)                   ((pte)->p != 0)
00105 #define PTE_GET_FRAME_ARCH(pte)                 ((pte)->pfn<<12)
00106 #define PTE_WRITABLE_ARCH(pte)                  ((pte)->w != 0)
00107 #define PTE_EXECUTABLE_ARCH(pte)                1
00108 
00109 #ifndef __ASM__
00110 
00111 #include <arch/mm/tlb.h>
00112 #include <mm/page.h>
00113 #include <arch/mm/frame.h>
00114 #include <arch/types.h>
00115 
00116 static inline int get_pt_flags(pte_t *pt, index_t i)
00117 {
00118         pte_t *p = &pt[i];
00119         
00120         return (
00121                 (p->cacheable<<PAGE_CACHEABLE_SHIFT) |
00122                 ((!p->p)<<PAGE_PRESENT_SHIFT) |
00123                 (1<<PAGE_USER_SHIFT) |
00124                 (1<<PAGE_READ_SHIFT) |
00125                 ((p->w)<<PAGE_WRITE_SHIFT) |
00126                 (1<<PAGE_EXEC_SHIFT) |
00127                 (p->g<<PAGE_GLOBAL_SHIFT)
00128         );
00129                 
00130 }
00131 
00132 static inline void set_pt_flags(pte_t *pt, index_t i, int flags)
00133 {
00134         pte_t *p = &pt[i];
00135         
00136         p->cacheable = (flags & PAGE_CACHEABLE) != 0;
00137         p->p = !(flags & PAGE_NOT_PRESENT);
00138         p->g = (flags & PAGE_GLOBAL) != 0;
00139         p->w = (flags & PAGE_WRITE) != 0;
00140         
00141         /*
00142          * Ensure that valid entries have at least one bit set.
00143          */
00144         p->soft_valid = 1;
00145 }
00146 
00147 extern void page_arch_init(void);
00148 
00149 #endif /* __ASM__ */
00150 
00151 #endif /* KERNEL */
00152 
00153 #endif
00154 

Generated on Sun Jun 18 17:01:57 2006 for HelenOS Kernel (mips32) by  doxygen 1.4.6