00001
00002
00003
00004
00005
00006
00007
00008 #ifndef PAGING_H
00009 #define PAGING_H
00010
00011
00012 #include <kernel/kernel_map.h>
00013
00014
00015 #define PAGE_SIZE 4096U
00016
00017
00018 #define P_PRESENT 0x01
00019
00020 #define P_WRITE 0x02
00021
00022 #define P_USER 0x04
00023
00024 #define P_ACCESSED 0x20
00025
00026 #define P_DIRTY 0x40
00027
00028
00029 #define P_ADDR_16MB (0x1000000 / PAGE_SIZE)
00030
00031 #define P_ADDR_4GB 0x100000
00032
00033
00034 #define PAGE_ALIGN_UP(addr) (((addr) + PAGE_SIZE - 1) & -PAGE_SIZE)
00035
00036 #define PAGE_ALIGN(addr) ((addr) & -PAGE_SIZE)
00037
00038 #define PAGE_DIR_ALIGN_UP(addr) (((addr) & -(PAGE_SIZE*1024)) + PAGE_SIZE*1024)
00039
00040 #define PAGE_DIR_ALIGN(addr) ((addr) & -(PAGE_SIZE*1024))
00041
00042
00043 #define ADDR_TO_PAGE(addr) (addr / PAGE_SIZE)
00044
00045 #define PAGE_TO_ADDR(p_addr) (p_addr * PAGE_SIZE)
00046
00047 #define GET_PDBR() (*ADDR_TO_PDE(PAGE_TABLE_MAP) & -PAGE_SIZE)
00048
00049
00050
00051 #define ADDR_TO_PDE(addr) (dword *)(PAGE_DIR_MAP + (((dword) (addr) / (1024 * 1024))&(~0x3)))
00052
00053
00054
00055 #define ADDR_TO_PTE(addr) (dword *)(PAGE_TABLE_MAP + ((((dword) (addr) / 1024))&(~0x3)))
00056
00057
00058 #define PHYSICAL(addr) (addr+PHYS_MEM_START)
00059
00060
00061 typedef struct PAGE_TABLE
00062 {
00063 dword entry[1024];
00064 } page_table_t;
00065
00066
00067
00068
00069 #define flush_tlb_single(addr) \
00070 __asm__ __volatile__("invlpg %0": :"m" (*(char *) addr))
00071
00072
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
00086
00087
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
00106
00107 #endif