page.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-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 __ia32_PAGE_H__
00036 #define __ia32_PAGE_H__
00037 
00038 #include <arch/mm/frame.h>
00039 
00040 #define PAGE_WIDTH      FRAME_WIDTH
00041 #define PAGE_SIZE       FRAME_SIZE
00042 
00043 #ifdef KERNEL
00044 
00045 #ifndef __ASM__
00046 #       define KA2PA(x) (((__address) (x)) - 0x80000000)
00047 #       define PA2KA(x) (((__address) (x)) + 0x80000000)
00048 #else
00049 #       define KA2PA(x) ((x) - 0x80000000)
00050 #       define PA2KA(x) ((x) + 0x80000000)
00051 #endif
00052 
00053 /*
00054  * Implementation of generic 4-level page table interface.
00055  * IA-32 has 2-level page tables, so PTL1 and PTL2 are left out.
00056  */
00057 #define PTL0_ENTRIES_ARCH       1024
00058 #define PTL1_ENTRIES_ARCH       0
00059 #define PTL2_ENTRIES_ARCH       0
00060 #define PTL3_ENTRIES_ARCH       1024
00061 
00062 #define PTL0_INDEX_ARCH(vaddr)  (((vaddr)>>22)&0x3ff)
00063 #define PTL1_INDEX_ARCH(vaddr)  0
00064 #define PTL2_INDEX_ARCH(vaddr)  0
00065 #define PTL3_INDEX_ARCH(vaddr)  (((vaddr)>>12)&0x3ff)
00066 
00067 #define GET_PTL1_ADDRESS_ARCH(ptl0, i)          ((pte_t *)((((pte_t *)(ptl0))[(i)].frame_address)<<12))
00068 #define GET_PTL2_ADDRESS_ARCH(ptl1, i)          (ptl1)
00069 #define GET_PTL3_ADDRESS_ARCH(ptl2, i)          (ptl2)
00070 #define GET_FRAME_ADDRESS_ARCH(ptl3, i)         ((__address)((((pte_t *)(ptl3))[(i)].frame_address)<<12))
00071 
00072 #define SET_PTL0_ADDRESS_ARCH(ptl0)             (write_cr3((__address) (ptl0)))
00073 #define SET_PTL1_ADDRESS_ARCH(ptl0, i, a)       (((pte_t *)(ptl0))[(i)].frame_address = (a)>>12)
00074 #define SET_PTL2_ADDRESS_ARCH(ptl1, i, a)
00075 #define SET_PTL3_ADDRESS_ARCH(ptl2, i, a)
00076 #define SET_FRAME_ADDRESS_ARCH(ptl3, i, a)      (((pte_t *)(ptl3))[(i)].frame_address = (a)>>12)
00077 
00078 #define GET_PTL1_FLAGS_ARCH(ptl0, i)            get_pt_flags((pte_t *)(ptl0), (index_t)(i))
00079 #define GET_PTL2_FLAGS_ARCH(ptl1, i)            PAGE_PRESENT
00080 #define GET_PTL3_FLAGS_ARCH(ptl2, i)            PAGE_PRESENT
00081 #define GET_FRAME_FLAGS_ARCH(ptl3, i)           get_pt_flags((pte_t *)(ptl3), (index_t)(i))
00082 
00083 #define SET_PTL1_FLAGS_ARCH(ptl0, i, x)         set_pt_flags((pte_t *)(ptl0), (index_t)(i), (x))
00084 #define SET_PTL2_FLAGS_ARCH(ptl1, i, x)
00085 #define SET_PTL3_FLAGS_ARCH(ptl2, i, x)
00086 #define SET_FRAME_FLAGS_ARCH(ptl3, i, x)        set_pt_flags((pte_t *)(ptl3), (index_t)(i), (x))
00087 
00088 #define PTE_VALID_ARCH(p)                       (*((__u32 *) (p)) != 0)
00089 #define PTE_PRESENT_ARCH(p)                     ((p)->present != 0)
00090 #define PTE_GET_FRAME_ARCH(p)                   ((p)->frame_address<<FRAME_WIDTH)
00091 #define PTE_WRITABLE_ARCH(p)                    ((p)->writeable != 0)
00092 #define PTE_EXECUTABLE_ARCH(p)                  1
00093 
00094 #ifndef __ASM__
00095 
00096 #include <mm/page.h>
00097 #include <arch/types.h>
00098 #include <arch/mm/frame.h>
00099 #include <typedefs.h>
00100 
00101 /* Page fault error codes. */
00102 
00104 #define PFERR_CODE_P            (1<<0)
00105 
00107 #define PFERR_CODE_RW           (1<<1)
00108 
00110 #define PFERR_CODE_US           (1<<2)
00111 
00113 #define PFERR_CODE_RSVD         (1<<3)  
00114 
00116 struct page_specifier {
00117         unsigned present : 1;
00118         unsigned writeable : 1;
00119         unsigned uaccessible : 1;
00120         unsigned page_write_through : 1;
00121         unsigned page_cache_disable : 1;
00122         unsigned accessed : 1;
00123         unsigned dirty : 1;
00124         unsigned pat : 1;
00125         unsigned global : 1;
00126         unsigned soft_valid : 1;        
00127         unsigned avl : 2;
00128         unsigned frame_address : 20;
00129 } __attribute__ ((packed));
00130 
00131 static inline int get_pt_flags(pte_t *pt, index_t i)
00132 {
00133         pte_t *p = &pt[i];
00134         
00135         return (
00136                 (!p->page_cache_disable)<<PAGE_CACHEABLE_SHIFT |
00137                 (!p->present)<<PAGE_PRESENT_SHIFT |
00138                 p->uaccessible<<PAGE_USER_SHIFT |
00139                 1<<PAGE_READ_SHIFT |
00140                 p->writeable<<PAGE_WRITE_SHIFT |
00141                 1<<PAGE_EXEC_SHIFT |
00142                 p->global<<PAGE_GLOBAL_SHIFT
00143         );
00144 }
00145 
00146 static inline void set_pt_flags(pte_t *pt, index_t i, int flags)
00147 {
00148         pte_t *p = &pt[i];
00149         
00150         p->page_cache_disable = !(flags & PAGE_CACHEABLE);
00151         p->present = !(flags & PAGE_NOT_PRESENT);
00152         p->uaccessible = (flags & PAGE_USER) != 0;
00153         p->writeable = (flags & PAGE_WRITE) != 0;
00154         p->global = (flags & PAGE_GLOBAL) != 0;
00155         
00156         /*
00157          * Ensure that there is at least one bit set even if the present bit is cleared.
00158          */
00159         p->soft_valid = true;
00160 }
00161 
00162 extern void page_arch_init(void);
00163 extern void page_fault(int n, istate_t *istate);
00164 
00165 #endif /* __ASM__ */
00166 
00167 #endif /* KERNEL */
00168 
00169 #endif
00170 

Generated on Sun Jun 18 16:38:51 2006 for HelenOS Kernel (ia32) by  doxygen 1.4.6