Main Page | Directories | File List | Globals

pgmap.c

Go to the documentation of this file.
00001 /*
00002  * kernel_arch/i386/kernel/memory/pgmap.c
00003  *
00004  * Copyright (c) 2003-2004 Lukasz Dembinski <dembol@nasa.com.pl>
00005  * All Rights Reserved
00006  * 
00007  * Date:        2004/01
00008  * Author:      Lukasz Dembinski
00009  * Info:        pgmap.c core file
00010  * Contact:     mailto: <dembol@nasa.com.pl>
00011  *
00012  */
00013 
00014 #include <agnix/agnix.h>
00015 #include <agnix/init.h>
00016 #include <agnix/memory.h>
00017 #include <asm/paging.h>
00018 #include <asm/cpu_ops.h>
00019 #include <agnix/console.h>
00020 
00021 #define DEBUG_MEM               0
00022 #define MOD_NAME                "MEM: "
00023 
00024 extern struct main_memory_s main_memory;
00025 
00026 struct pte_s *pte_ptr(struct pde_s *pde)
00027 {
00028     struct pte_s *pte;
00029     
00030     if (!pte_address(pde)) {
00031         pte = (struct pte_s *)get_free_pages(0);
00032         pde->pte_addr = virt_to_phys((u32)pte);
00033         set_pde(pde, make_pde_phys(pde->pte_addr, PDE_FLAG_P | PDE_FLAG_RW));
00034     } else {
00035         pte = phys_to_virt(pte_address(pde));
00036     }
00037     
00038     return pte;
00039 }
00040 
00041 int remap_page_tables(u32 pd_addr, u32 from, u32 to, u32 len)
00042 {
00043     
00044 
00045     return 0;    
00046 }
00047 
00048 int remap_kpage_tables(u32 from, u32 to, u32 len)
00049 {
00050     return remap_page_tables(main_memory.pdbr, from, to, len);
00051 }
00052 
00053 int page_tables_init(struct main_memory_s *mem)
00054 {
00055     struct pde_s *pde;
00056     struct pte_s *pte;
00057     u32    page_start;
00058     u32    page_end;
00059     u32    page_len;
00060     u32    page_count;
00061     int    i, j;
00062 
00063 #if DEBUG_MEM    
00064     printk(MOD_NAME "Initializing page tables\n");
00065 #endif
00066 
00067     page_count = 0;
00068     page_start = 0;
00069     page_end   = (mem->mem_size) >> 2; // KB >> 2 == pages 
00070     page_len = page_end - page_start;
00071 
00072     pde = (struct pde_s *)mem->pdbr;
00073     pde += pde_offset(PAGE_OFFSET);
00074 
00075 #if DEBUG_MEM
00076     printk(MOD_NAME "page count = %d\n", page_len);
00077 #endif
00078 
00079     __cli();
00080 
00081 //    write_cr4(read_cr4() | 0x10);
00082 
00083     for (i = pde_offset(PAGE_OFFSET); i < PDE_PER_PD; i++) {
00084 
00085 //      pde->pte_addr = (page_count << PAGE_SHIFT);     
00086 //      set_pde(pde, make_pde_phys(pde->pte_addr, PDE_FLAG_P | PDE_FLAG_RW | PDE_FLAG_PS));
00087 //      pde++;
00088 //      page_count += 1024;
00089 //    
00090         pte = pte_ptr(pde);
00091         for (j = 0; j < PTE_PER_PT; j++) {
00092 
00093             set_pte(pte, make_pte_phys(page_count << PAGE_SHIFT, (PTE_FLAG_P | PTE_FLAG_RW | PTE_FLAG_A | PTE_FLAG_D)));                
00094 
00095             if (++page_count >= page_len)
00096                 break;
00097 
00098             pte++;
00099         }
00100         
00101         if (page_count >= page_len)
00102             break;
00103         
00104         pde++;
00105     }
00106 
00107 
00108 #if DEBUG_MEM
00109     printk(MOD_NAME "Loading cr3 (phys_addr=%x) ... ", virt_to_phys(mem->pdbr));
00110 #endif
00111 
00112     load_cr3(mem->pdbr);
00113     
00114 #if DEBUG_MEM
00115     printk("ok\n");
00116 #endif
00117 
00118     return 0;
00119 }
Dokumentacje wygenerowano programem Doxygen 1.4.2 dla projektu Agnix