Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

paging.h

Go to the documentation of this file.
00001 /*!     \file include/arch/paging.h
00002  *      \brief Paging header.
00003  *      \author Andrea Righi <drizzt@inwind.it>
00004  *      \date Last update: 2003-12-16
00005  *      \note Copyright (&copy;) 2003 Andrea Righi
00006  */
00007 
00008 #ifndef PAGING_H
00009 #define PAGING_H
00010 
00011 // Kernel virtual memory map                                            //
00012 #include <kernel/kernel_map.h>
00013 
00014 //! The page size.
00015 #define PAGE_SIZE       4096U
00016 
00017 //! Page present flag.
00018 #define P_PRESENT       0x01
00019 //! Page writeable flag.
00020 #define P_WRITE         0x02
00021 //! Page at user privilege level.
00022 #define P_USER          0x04
00023 //! Page accessed flag.
00024 #define P_ACCESSED      0x20
00025 //! Page dirty flag (the page has been written).
00026 #define P_DIRTY         0x40
00027 
00028 //! 16MB expressed in pages.
00029 #define P_ADDR_16MB             (0x1000000 / PAGE_SIZE)
00030 //! 4GB expressed in pages.
00031 #define P_ADDR_4GB              0x100000
00032 
00033 //! Rounds an address up to a page boundary.
00034 #define PAGE_ALIGN_UP(addr)     (((addr) + PAGE_SIZE - 1) & -PAGE_SIZE)
00035 //! Rounds an address down to a page boundary.
00036 #define PAGE_ALIGN(addr)        ((addr) & -PAGE_SIZE)
00037 //! Rounds an address up to a page directory boundary.
00038 #define PAGE_DIR_ALIGN_UP(addr) (((addr) & -(PAGE_SIZE*1024)) + PAGE_SIZE*1024)
00039 //! Rounds an address down to a page directory boundary.
00040 #define PAGE_DIR_ALIGN(addr)    ((addr) & -(PAGE_SIZE*1024))
00041 
00042 //! Converts from address to page.
00043 #define ADDR_TO_PAGE(addr)      (addr / PAGE_SIZE)
00044 //! Converts from page to address
00045 #define PAGE_TO_ADDR(p_addr)    (p_addr * PAGE_SIZE)
00046 //! Get current page directory base address.
00047 #define GET_PDBR()              (*ADDR_TO_PDE(PAGE_TABLE_MAP) & -PAGE_SIZE)
00048 
00049 //! Access to the page directory entry referred to the
00050 //! virtual address \p addr.
00051 #define ADDR_TO_PDE(addr)       (dword *)(PAGE_DIR_MAP + (((dword) (addr) / (1024 * 1024))&(~0x3)))
00052 
00053 //! Access to the page table entry referred to the
00054 //! virtual address \p addr.
00055 #define ADDR_TO_PTE(addr)       (dword *)(PAGE_TABLE_MAP + ((((dword) (addr) / 1024))&(~0x3)))
00056 
00057 //! Access to an address into the mapped physical memory area.
00058 #define PHYSICAL(addr)          (addr+PHYS_MEM_START)
00059 
00060 //! Page table structure.
00061 typedef struct PAGE_TABLE
00062 {
00063         dword entry[1024];
00064 } page_table_t;
00065 
00066 //! Flush a single entry into the TLB cache (address translation).
00067 //! \param addr
00068 //!     The virtual address of the page that must be invalidated.
00069 #define flush_tlb_single(addr) \
00070         __asm__ __volatile__("invlpg %0": :"m" (*(char *) addr))
00071 
00072 //! Flush every entry into the TLB cache (address translation).
00073 #define flush_tlb_all() \
00074         do {                                                            \
00075                 unsigned int tmpreg;                                    \
00076                                                                         \
00077                 __asm__ __volatile__(                                   \
00078                         "movl %%cr3, %0;  # flush TLB \n"               \
00079                         "movl %0, %%cr3;              \n"               \
00080                         : "=r" (tmpreg)                                 \
00081                         :: "memory");                                   \
00082         } while (0)
00083 
00084 
00085 /** \ingroup Memory
00086  *  \defgroup Paging Paging
00087  *  The page manager module.
00088  *  @{
00089  */
00090 
00091 void init_paging();
00092 dword pop_frame();
00093 void push_frame(dword p_addr);
00094 bool map_page(dword vir_addr, dword phys_addr, word attribs);
00095 void unmap_page(dword vir_addr);
00096 void delete_page(dword vir_addr);
00097 void *get_temp_page();
00098 void free_temp_page(void *p, bool do_delete);
00099 dword vir_to_phys(dword vir_addr);
00100 int page_fault_handler(dword err_code, dword cr2);
00101 void dump_dirty_pages();
00102 void dump_free_frames();
00103 void check_free_frames_integrity();
00104 
00105 /** @} */ // end of Paging
00106 
00107 #endif

Generated on Fri Feb 20 15:32:16 2004 for Minirighi by doxygen1.2.18