Created Virtual Memory Manager interface
This commit is contained in:
parent
6c8de51b44
commit
2bdb05a01a
|
@ -0,0 +1,71 @@
|
|||
#ifndef VMM_H_
|
||||
#define VMM_H_
|
||||
|
||||
/*
|
||||
* vmm_init:
|
||||
* Initialize the Virtual Memory Manager.
|
||||
*
|
||||
*/
|
||||
|
||||
void vmm_init(void);
|
||||
|
||||
/*
|
||||
* vmm_ptable_search:
|
||||
* Given a virtual address, search for its corresponding entry
|
||||
* in Page Table.
|
||||
*
|
||||
* @param ptable - Pointer to the beginning of the Page Table
|
||||
* @param virt_addr - Virtual address
|
||||
*
|
||||
* @return - Pointer to corresponding Page Table entry
|
||||
*
|
||||
*/
|
||||
|
||||
uint32_t *vmm_ptable_search(uint32_t *ptable, uint32_t virt_addr);
|
||||
|
||||
/*
|
||||
* vmm_pdir_search:
|
||||
* Given a virtual address, search for its corresponding entry
|
||||
* in Page Directory.
|
||||
*
|
||||
* @param pdir - Pointer to the beginning of the Page Directory
|
||||
* @param virt_addr - Virtual address
|
||||
*
|
||||
* @return - Pointer to corresponding Page Directory entry
|
||||
*
|
||||
*/
|
||||
|
||||
uint32_t *vmm_pdir_search(uint32_t *pdir, uint32_t virt_addr);
|
||||
|
||||
/*
|
||||
* vmm_install_pdir:
|
||||
* Install a Page Directory.
|
||||
*
|
||||
* @param pdir - Pointer to a Page Directory
|
||||
*
|
||||
*/
|
||||
|
||||
void vmm_install_pdir(uint32_t *pdir);
|
||||
|
||||
/*
|
||||
* vmm_flush_tlb:
|
||||
* Flush the Translation Lookaside Buffer.
|
||||
*
|
||||
* @param virt_tlb - Virtual address of TLB
|
||||
*
|
||||
*/
|
||||
|
||||
void vmm_flush_tlb(uint32_t virt_tlb);
|
||||
|
||||
/*
|
||||
* vmm_map_page:
|
||||
* Maps physical address to virtual address.
|
||||
*
|
||||
* @param phys - Physical address
|
||||
* @param virt - Virtual address
|
||||
*
|
||||
*/
|
||||
|
||||
void vmm_map_addr(uint32_t phys, uint32_t virt);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,48 @@
|
|||
#ifndef PE_H_
|
||||
#define PE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* The following routines serve as a common interface for Page Directory and
|
||||
* Page Table entries.
|
||||
*
|
||||
*/
|
||||
|
||||
/* Page Entry Flags. */
|
||||
|
||||
enum PE_FLAGS {
|
||||
|
||||
PE_PRESENT = 0x01,
|
||||
PE_WRITABLE = 0x02,
|
||||
PE_USER = 0x04,
|
||||
PE_PWT = 0x08,
|
||||
PE_PCD = 0x10,
|
||||
PE_ACCESSED = 0x20,
|
||||
PE_DIRTY = 0x40,
|
||||
PE_4MB = 0x80,
|
||||
PE_CPU_GLOBAL = 0x100,
|
||||
PE_LV4_GLOBAL = 0x200,
|
||||
PE_FRAME = 0xFFFFF000
|
||||
|
||||
};
|
||||
|
||||
inline void pe_set_attr(uint32_t *e, uint32_t attr) { *e |= attr; }
|
||||
|
||||
inline void pe_unset_attr(uint32_t *e, uint32_t attr) { *e &= ~attr; }
|
||||
|
||||
void pe_set_frame(uint32_t *e, uint32_t addr) {
|
||||
*e = (*e & ~PE_FRAME) | (addr << 12);
|
||||
}
|
||||
|
||||
inline uint32_t pe_get_frame (uint32_t e) { return e & PE_FRAME; }
|
||||
|
||||
inline int pe_is_present (uint32_t e) { return e & PE_PRESENT; }
|
||||
|
||||
inline int pe_is_writable (uint32_t e) { return e & PE_WRITABLE; }
|
||||
|
||||
inline int pe_is_user (uint32_t e) { return e & PE_USER; }
|
||||
|
||||
inline int pe_is_4mb (uint32_t e) { return e & PE_4MB; }
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue