x86: add API for modifying page tables

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2017-07-14 17:39:47 -07:00 committed by Anas Nashif
commit 6101aa6220
2 changed files with 73 additions and 16 deletions

View file

@ -159,3 +159,46 @@ int _x86_mmu_buffer_validate(void *addr, size_t size, int flags)
}
return status;
}
static inline void tlb_flush_page(void *addr)
{
/* Invalidate TLB entries corresponding to the page containing the
* specified address
*/
char *page = (char *)addr;
__asm__ ("invlpg %0" :: "m" (*page));
}
void _x86_mmu_set_flags(void *ptr, size_t size, u32_t flags, u32_t mask)
{
int pde_index, pte_index;
union x86_mmu_pde *pde;
union x86_mmu_pte *pte;
struct x86_mmu_page_table *pt;
u32_t addr = (u32_t)ptr;
__ASSERT(!(addr & MMU_PAGE_MASK), "unaligned address provided");
__ASSERT(!(size & MMU_PAGE_MASK), "unaligned size provided");
while (size) {
pde_index = MMU_PDE_NUM(addr);
pde = &X86_MMU_PD->entry[pde_index];
/* TODO we're not generating 4MB entries at the moment */
__ASSERT(pde->fourmb.ps != 1, "4MB PDE found");
pt = (struct x86_mmu_page_table *)(pde->pt.page_table << 12);
pte_index = MMU_PAGE_NUM(addr);
pte = &pt->entry[pte_index];
pte->value = (pte->value & ~mask) | flags;
tlb_flush_page((void *)addr);
size -= MMU_PAGE_SIZE;
addr += MMU_PAGE_SIZE;
}
}

View file

@ -457,22 +457,6 @@ extern void _arch_irq_enable(unsigned int irq);
*/
extern void _arch_irq_disable(unsigned int irq);
/**
* @brief check page table entry flags
*
* This routine checks if the buffer is avaialable to the whoever calls
* this API.
* @param addr start address of the buffer
* @param size the size of the buffer
* @param flags permisions to check.
* Consists of 2 bits the bit0 represents the RW permissions
* The bit1 represents the user/supervisor permissions
* Use macro BUFF_READABLE/BUFF_WRITEABLE or BUFF_USER to build the flags
*
* @return true-if the permissions of the pde matches the request
*/
int _x86_mmu_buffer_validate(void *addr, size_t size, int flags);
/**
* @defgroup float_apis Floating Point APIs
* @ingroup kernel_apis
@ -587,6 +571,36 @@ extern u32_t __mmu_tables_start;
#define X86_MMU_PD ((struct x86_mmu_page_directory *)\
(void *)&__mmu_tables_start)
/**
* @brief set flags in the MMU page tables
*
* Modify bits in the existing page tables for a particular memory
* range, which must be page-aligned
*
* @param ptr Starting memory address which must be page-aligned
* @param size Size of the region, must be page size multiple
* @flags Value of bits to set in the page table entries
* @mask Mask indicating which particular bits in the page table entries to
* modify
*/
void _x86_mmu_set_flags(void *ptr, size_t size, u32_t flags, u32_t mask);
/**
* @brief check page table entry flags
*
* This routine checks if the buffer is avaialable to the whoever calls
* this API.
* @param addr start address of the buffer
* @param size the size of the buffer
* @param flags permisions to check.
* Consists of 2 bits the bit0 represents the RW permissions
* The bit1 represents the user/supervisor permissions
* Use macro BUFF_READABLE/BUFF_WRITEABLE or BUFF_USER to build the flags
*
* @return true-if the permissions of the pde matches the request
*/
int _x86_mmu_buffer_validate(void *addr, size_t size, int flags);
#endif /* CONFIG_X86_MMU */
#endif /* !_ASMLANGUAGE */