本文整理汇总了C++中PTX函数的典型用法代码示例。如果您正苦于以下问题:C++ PTX函数的具体用法?C++ PTX怎么用?C++ PTX使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PTX函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: set_page_data
int
set_page_data(struct DataTable *tbl, void *va, data_t id)
{
int i;
pge_t *pge = &(tbl->table)[PGX(va)];
if(! *pge) {
pthread_mutex_lock(&tbl->lock);
*pge = malloc(sizeof(pue_t) * TBLENTRIES);
memset(*pge, 0, sizeof(pue_t) * TBLENTRIES);
pthread_mutex_unlock(&tbl->lock);
}
pue_t *pue = &(*pge)[PUX(va)];
if(! *pue) {
pthread_mutex_lock(&tbl->lock);
*pue = malloc(sizeof(pme_t) * TBLENTRIES);
memset(*pue, 0, sizeof(pme_t) * TBLENTRIES);
pthread_mutex_unlock(&tbl->lock);
}
pme_t *pme = &(*pue)[PMX(va)];
if(! *pme) {
pthread_mutex_lock(&tbl->lock);
*pme = malloc(sizeof(data_t) * TBLENTRIES);
memset(*pme, 0, sizeof(data_t) * TBLENTRIES);
pthread_mutex_unlock(&tbl->lock);
}
DEBUG_LOG("set_page_data of %p from %lu to %lu", va, (*pme)[PTX(va)], id);
(*pme)[PTX(va)] = id;
return 0;
}
开发者ID:katfang,项目名称:dsm,代码行数:34,代码来源:pagedata.c
示例2: checkmmu
void
checkmmu(ulong va, ulong pa)
{
ulong *pdb, *pte;
int pdbx;
if(up->mmupdb == 0)
return;
pdb = mmupdb(up->mmupdb, va);
pdbx = PDX(va);
if(MAPPN(pdb[pdbx]) == 0){
/* okay to be empty - will fault and get filled */
return;
}
pte = KADDR(MAPPN(pdb[pdbx]));
if(MAPPN(pte[PTX(va)]) != pa){
if(!paemode)
print("%ld %s: va=0x%08lux pa=0x%08lux pte=0x%08lux (0x%08lux)\n",
up->pid, up->text,
va, pa, pte[PTX(va)], MAPPN(pte[PTX(va)]));
else
print("%ld %s: va=0x%08lux pa=0x%08lux pte=0x%16llux (0x%08lux)\n",
up->pid, up->text,
va, pa, *(uvlong*)&pte[PTX(va)], MAPPN(pte[PTX(va)]));
}
}
开发者ID:Nurb432,项目名称:plan9front,代码行数:28,代码来源:mmu.c
示例3: gpio_Interrupt_init
/*************************************************************************
* 蓝宙电子科技有限公司
*
* 函数名称:gpio_Interrupt_init
* 功能说明:初始化gpio
* 参数说明:PTxn 端口号(PORTA,PORTD)
* IO 引脚方向,0=输入,1=输出,输入输出状态定义____________(修改:这个函数中只有定义为输入模式有效,否则不改变相关状态)
* mode 中断模式
* 函数返回:无
* 修改时间:2012-9-15 已测试
* 备 注:
*************************************************************************/
void gpio_Interrupt_init(PTxn ptxn, GPIO_CFG cfg, GPIO_INP mode)
{
ASSERT( (PTn(ptxn) < 32u) ); //使用断言检查输入、电平 是否为1bit
//选择功能脚 PORTx_PCRx ,每个端口都有个寄存器 PORTx_PCRx
PORT_PCR_REG(PORTX_BASE(ptxn), PTn(ptxn)) = (0 | PORT_PCR_MUX(1) | cfg | PORT_PCR_IRQC(mode) );
//选择功能脚 PORTx_PCRx ,每个端口都有中断模型
// PORT_DFER_REG(PORTX_BASE(ptxn)) = PORT_DFER_DFE( 1<<PTn(ptxn));
//端口方向控制输入还是输出
if( ( (cfg & 0x01) == GPI) || (cfg == GPI_UP) || (cfg == GPI_UP_PF)
|| (cfg == GPI_DOWN) || (cfg == GPI_DOWN_PF) )
// 最低位为0则输入 || 输入上拉模式 || 输入上拉,带无源滤波器
{
GPIO_PDDR_REG(GPIOX_BASE(ptxn)) &= ~(1 << PTn(ptxn)); //设置端口方向为输入
}
if(PTX(ptxn)==0)
enable_irq(PortA_irq_no);
else if(PTX(ptxn)==3)
enable_irq(PortD_irq_no);
}
开发者ID:forbelief,项目名称:KL25EM,代码行数:37,代码来源:gpio.c
示例4: gpio_set
/*************************************************************************
* 蓝宙电子工作室
*
* 函数名称:gpio_set
* 功能说明:设置引脚状态
* 参数说明:ptxn:端口号(gpio.h中宏定义,gpio_cfg.h)
* state 输出初始状态,0=低电平,1=高电平
* 函数返回:无
* 修改时间:2012-1-16 已测试
* 备 注:_____________________________________(修改过)
*************************************************************************/
void gpio_set(PTxn ptxn, uint8_t state)
{
if(state == 1)
GPIO_SET(PTX(ptxn), PTn(ptxn), 1);
else
GPIO_SET(PTX(ptxn), PTn(ptxn), 0);
}
开发者ID:forbelief,项目名称:KL25EM,代码行数:18,代码来源:gpio.c
示例5: pgdir_walk
// Given 'pgdir', a pointer to a page directory, pgdir_walk returns
// a pointer to the page table entry (PTE) for linear address 'va'.
// This requires walking the two-level page table structure.
//
// The relevant page table page might not exist yet.
// If this is true, and create == false, then pgdir_walk returns NULL.
// Otherwise, pgdir_walk allocates a new page table page with page_alloc.
// - If the allocation fails, pgdir_walk returns NULL.
// - Otherwise, the new page's reference count is incremented,
// the page is cleared,
// and pgdir_walk returns a pointer into the new page table page.
//
// Hint 1: you can turn a Page * into the physical address of the
// page it refers to with page2pa() from kern/pmap.h.
//
// Hint 2: the x86 MMU checks permission bits in both the page directory
// and the page table, so it's safe to leave permissions in the page
// directory more permissive than strictly necessary.
//
// Hint 3: look at inc/mmu.h for useful macros that mainipulate page
// table and page directory entries.
//
pte_t *
pgdir_walk(pde_t *pgdir, const void *va, int create)
{
// Fill this function in
pte_t * pte;
if ((pgdir[PDX(va)] & PTE_P) != 0) {
pte =(pte_t *) KADDR(PTE_ADDR(pgdir[PDX(va)]));
return pte + PTX(va);
}
if(create != 0) {
struct PageInfo *tmp;
tmp = page_alloc(1);
if(tmp != NULL) {
tmp->pp_ref += 1;
tmp->pp_link = NULL;
pgdir[PDX(va)] = page2pa(tmp) | PTE_U | PTE_W | PTE_P;
pte = (pte_t *)KADDR(page2pa(tmp));
return pte+PTX(va);
}
}
return NULL;
}
开发者ID:liuxu1005,项目名称:Operating-System-Engineering,代码行数:54,代码来源:pmap.c
示例6: pgdir_walk
pte_t* pgdir_walk(pde_t *pgdir, const void *va, int create)
{
// Fill this function in
if(!pgdir){
cprintf("ERROR!!\n");
}
//Get the entry id in the page directory
uintptr_t pgdir_offset = (uintptr_t)PDX(va);
pte_t *ptentry;
//if page directory entry does not exsist.
if(!(pgdir[pgdir_offset] & PTE_P)) {
if(!create)
return NULL;
struct PageInfo *new_page = page_alloc(ALLOC_ZERO);
if(!new_page)
return NULL;
new_page->pp_ref++;
pgdir[pgdir_offset] = (page2pa(new_page)) | PTE_P | PTE_W | PTE_U;
//Returning pointer to page table base.
//return (pte_t*) (page2kva(new_page));
//Returning pointer to page table entry
pde_t *ret_arr = page2kva(new_page);
return &ret_arr[PTX(va)];
} else {
ptentry = KADDR(PTE_ADDR(pgdir[pgdir_offset]));
return &(ptentry[PTX(va)]);
}
}
开发者ID:ajtheprogod,项目名称:os_programs,代码行数:30,代码来源:pmap.c
示例7: pgdir_walk
// Given 'pgdir', a pointer to a page directory, pgdir_walk returns
// a pointer to the page table entry (PTE) for linear address 'va'.
// This requires walking the two-level page table structure.
//
// The relevant page table page might not exist yet.
// If this is true, and create == false, then pgdir_walk returns NULL.
// Otherwise, pgdir_walk allocates a new page table page with page_alloc.
// - If the allocation fails, pgdir_walk returns NULL.
// - Otherwise, the new page's reference count is incremented,
// the page is cleared,
// and pgdir_walk returns a pointer into the new page table page.
//
// Hint 1: you can turn a Page * into the physical address of the
// page it refers to with page2pa() from kern/pmap.h.
//
// Hint 2: the x86 MMU checks permission bits in both the page directory
// and the page table, so it's safe to leave permissions in the page
// directory more permissive than strictly necessary.
//
// Hint 3: look at inc/mmu.h for useful macros that mainipulate page
// table and page directory entries.
//
pte_t *
pgdir_walk(pde_t *pgdir, const void *va, int create)
{
pte_t * pgtbl = NULL;
if(!(pgdir[PDX(va)] & PTE_P)) {
if(!create) {
return NULL;
} else {
struct Page * new_pgtbl = page_alloc(ALLOC_ZERO);
if(new_pgtbl){
new_pgtbl->pp_ref += 1;
pgdir[PDX(va)] = (physaddr_t) page2pa(new_pgtbl) | PTE_P | PTE_W |
PTE_U;
pgtbl = (pte_t *) KADDR(PTE_ADDR(pgdir[PDX(va)]));
return &pgtbl[PTX(va)];
} else
return NULL;
}
} else
pgtbl = (pte_t *) KADDR(PTE_ADDR(pgdir[PDX(va)]));
return &pgtbl[PTX(va)];
}
开发者ID:taylorr7732,项目名称:os_dev_tcr,代码行数:50,代码来源:pmap.c
示例8: pgdir_walk
// Given 'pgdir', a pointer to a page directory, pgdir_walk returns
// a pointer to the page table entry (PTE) for linear address 'va'.
// This requires walking the two-level page table structure.
//
// The relevant page table page might not exist yet.
// If this is true, and create == false, then pgdir_walk returns NULL.
// Otherwise, pgdir_walk allocates a new page table page with page_alloc.
// - If the allocation fails, pgdir_walk returns NULL.
// - Otherwise, the new page's reference count is incremented,
// the page is cleared,
// and pgdir_walk returns a pointer into the new page table page.
//
// Hint 1: you can turn a Page * into the physical address of the
// page it refers to with page2pa() from kern/pmap.h.
//
// Hint 2: the x86 MMU checks permission bits in both the page directory
// and the page table, so it's safe to leave permissions in the page
// more permissive than strictly necessary.
//
// Hint 3: look at inc/mmu.h for useful macros that mainipulate page
// table and page directory entries.
//
pte_t *
pgdir_walk(pde_t *pgdir, const void *va, int create)
{
// Fill this function in
struct Page* new_page;
pde_t* pde = pgdir + PDX(va);
pte_t* pte;
// has created
if (*pde & PTE_P) {
pte = (pte_t*)KADDR(PTE_ADDR(*pde));
return pte + PTX(va);
}
// need create
if (create == 0) {
return NULL;
} else {
new_page = page_alloc(ALLOC_ZERO);
if (new_page == NULL) {
return NULL;
} else {
new_page->pp_ref++;
*pde = page2pa(new_page) | PTE_P | PTE_W | PTE_U;
pte = (pte_t*)KADDR(PTE_ADDR(*pde));
return pte + PTX(va);
}
}
}
开发者ID:Azard,项目名称:SE315-OperatingSystem,代码行数:51,代码来源:pmap.c
示例9: KADDR
/*
hint from check
ptep = (pte_t *) KADDR(PTE_ADDR(kern_pgdir[PDX(PGSIZE)]));
assert(pgdir_walk(kern_pgdir, (void*)PGSIZE, 0) == ptep+PTX(PGSIZE));
*/
pte_t *
pgdir_walk(pde_t *pgdir, const void *va, int create)
{
// Fill this function in
pde_t *pde = pgdir + PDX(va);
pte_t *ptep = NULL;
if(*pde & PTE_P) { /* present */
ptep = KADDR(PTE_ADDR(*pde));
return ptep + PTX(va);
}
if(create == false) {
return NULL;
}
struct PageInfo *new_ptep = page_alloc(ALLOC_ZERO);
if(!new_ptep){
return NULL;
}
//assert( new_ptep != NULL );
//assert( new_ptep->pp_ref == 0 );
new_ptep->pp_ref = 1;
*pde = page2pa(new_ptep) | PTE_P | PTE_U;
ptep = page2kva(new_ptep);
return ptep + PTX(va);
}
开发者ID:DeepinDream,项目名称:6.828-MIT-OS,代码行数:31,代码来源:pmap.c
示例10: pgdir_walk
// Given 'pgdir', a pointer to a page directory, pgdir_walk returns
// a pointer to the page table entry (PTE) for linear address 'va'.
// This requires walking the two-level page table structure.
//
// The relevant page table page might not exist yet.
// If this is true, and create == false, then pgdir_walk returns NULL.
// Otherwise, pgdir_walk allocates a new page table page with page_alloc.
// - If the allocation fails, pgdir_walk returns NULL.
// - Otherwise, the new page's reference count is incremented,
// the page is cleared,
// and pgdir_walk returns a pointer into the new page table page.
//
// Hint 1: you can turn a Page * into the physical address of the
// page it refers to with page2pa() from kern/pmap.h.
//
// Hint 2: the x86 MMU checks permission bits in both the page directory
// and the page table, so it's safe to leave permissions in the page
// more permissive than strictly necessary.
//
// Hint 3: look at inc/mmu.h for useful macros that mainipulate page
// table and page directory entries.
//
pte_t *
pgdir_walk(pde_t *pgdir, const void *va, int create)
{
// Fill this function in
/*stone's solution for lab2*/
pde_t* pde = pgdir + PDX(va);//stone: get pde
if (*pde & PTE_P){//stone:if present
pte_t *pte = PTX(va) + (pte_t *)KADDR(PTE_ADDR(*pde));
return pte;
}
else if (create == 0)
return NULL;
else{
struct Page* pp = page_alloc(ALLOC_ZERO);
if (pp == NULL)
return NULL;
else{
pp->pp_ref = 1;
physaddr_t physaddr = page2pa(pp);
*pde = physaddr | PTE_U | PTE_W | PTE_P;
pte_t *pte = PTX(va) + (pte_t *)KADDR(PTE_ADDR(*pde));
return pte;
}
}
//return NULL;
}
开发者ID:stone-SJH,项目名称:joslabs-byStone,代码行数:48,代码来源:pmap.c
示例11: pgdir_walk
// Given 'pgdir', a pointer to a page directory, pgdir_walk returns
// a pointer to the page table entry (PTE) for linear address 'va'.
// This requires walking the two-level page table structure.
//
// The relevant page table page might not exist yet.
// If this is true, and create == false, then pgdir_walk returns NULL.
// Otherwise, pgdir_walk allocates a new page table page with page_alloc.
// - If the allocation fails, pgdir_walk returns NULL.
// - Otherwise, the new page's reference count is incremented,
// the page is cleared,
// and pgdir_walk returns a pointer into the new page table page.
//
// Hint 1: you can turn a Page * into the physical address of the
// page it refers to with page2pa() from kern/pmap.h.
//
// Hint 2: the x86 MMU checks permission bits in both the page directory
// and the page table, so it's safe to leave permissions in the page
// more permissive than strictly necessary.
//
// Hint 3: look at inc/mmu.h for useful macros that mainipulate page
// table and page directory entries.
//
pte_t *
pgdir_walk(pde_t *pgdir, const void *va, int create)
{
if (pgdir == NULL) {
panic("pgdir_walk: pgdir is NULL\n");
}
pde_t pde = pgdir[PDX(va)];
// If page table page is present
if (pde & PTE_P) {
pte_t* pgt = KADDR(PTE_ADDR(pgdir[PDX(va)]));
return &pgt[PTX(va)];
}
// Otherwise page table page doesn't exist
if (!create) return NULL;
// Allocate new page table page (clear it as well)
struct Page* pp;
if (!(pp = page_alloc(ALLOC_ZERO))) return NULL;
pp->pp_ref++; // increment ref count
// set pde, for now permissions more permissive
pgdir[PDX(va)] = page2pa(pp) | PTE_P | PTE_W | PTE_U;
return &((pte_t*) page2kva(pp))[PTX(va)];
}
开发者ID:bosswissam,项目名称:djos,代码行数:50,代码来源:pmap.c
示例12: kmm_pgfault
void
kmm_pgfault(struct trapframe *tf)
{
// uint64_t err = tf->tf_err;
uintptr_t addr = rcr2();
if (addr >= PBASE && addr < PBASE + PSIZE)
{
pgd_t *pgd = KADDR_DIRECT(PTE_ADDR(rcr3()));
pud_t *pud;
pmd_t *pmd;
pte_t *ptd;
/* PHYSICAL ADDRRESS ACCESSING */
if (last_pgd != NULL)
{
pud = KADDR_DIRECT(PGD_ADDR(last_pgd[PGX(last_addr)]));
pmd = KADDR_DIRECT(PUD_ADDR(pud[PUX(last_addr)]));
ptd = KADDR_DIRECT(PMD_ADDR(pmd[PMX(last_addr)]));
ptd[PTX(last_addr)] = 0;
if (ptd == temp_ptd)
{
pmd[PUX(last_addr)] = 0;
if (pmd == temp_pmd)
{
pud[PUX(last_addr)] = 0;
if (pud == temp_pud)
last_pgd[PGX(last_addr)] = 0;
}
if (last_pgd == pgd)
{
invlpg((void *)last_addr);
}
}
}
if (pgd[PGX(last_addr)] == 0)
pgd[PGX(last_addr)] = PADDR_DIRECT(temp_pud) | PTE_W | PTE_P;
pud = KADDR_DIRECT(PGD_ADDR(pgd[PGX(last_addr)]));
if (pud[PUX(last_addr)] == 0)
pud[PUX(last_addr)] = PADDR_DIRECT(temp_pmd) | PTE_W | PTE_P;
pmd = KADDR_DIRECT(PUD_ADDR(pud[PUX(last_addr)]));
if (pmd[PMX(last_addr)] == 0)
pmd[PMX(last_addr)] = PADDR_DIRECT(temp_ptd) | PTE_W | PTE_P;
ptd = KADDR_DIRECT(PMD_ADDR(pmd[PMX(last_addr)]));
ptd[PTX(last_addr)] = PADDR_DIRECT(addr) | PTE_W | PTE_P;
last_pgd = pgd;
last_addr = addr;
/* XXX? */
// invlpg((void *)addr);
}
}
开发者ID:SteveHuang27,项目名称:ucore-x64-smp,代码行数:57,代码来源:kmm.c
示例13: check_va2pa
static physaddr_t
check_va2pa(pde_t *pgdir, uintptr_t va)
{
pte_t *p;
pgdir = &pgdir[PDX(va)];
if (!(*pgdir & PTE_P))
return ~0;
p = (pte_t*) KADDR(PTE_ADDR(*pgdir));
if (!(p[PTX(va)] & PTE_P))
return ~0;
return PTE_ADDR(p[PTX(va)]);
}
开发者ID:stone-SJH,项目名称:joslabs-byStone,代码行数:13,代码来源:pmap.c
示例14: pgdir_walk
// Given 'pgdir', a pointer to a page directory, pgdir_walk returns
// a pointer to the page table entry (PTE) for linear address 'va'.
// This requires walking the two-level page table structure.
//
// The relevant page table page might not exist yet.
// If this is true, and create == false, then pgdir_walk returns NULL.
// Otherwise, pgdir_walk allocates a new page table page with page_alloc.
// - If the allocation fails, pgdir_walk returns NULL.
// - Otherwise, the new page's reference count is incremented,
// the page is cleared,
// and pgdir_walk returns a pointer into the new page table page.
//
// Hint 1: you can turn a Page * into the physical address of the
// page it refers to with page2pa() from kern/pmap.h.
//
// Hint 2: the x86 MMU checks permission bits in both the page directory
// and the page table, so it's safe to leave permissions in the page
// directory more permissive than strictly necessary.
//
// Hint 3: look at inc/mmu.h for useful macros that mainipulate page
// table and page directory entries.
//
pte_t *
pgdir_walk(pde_t *pgdir, const void *va, int create)
{
// Fill this function in
pde_t* pd = pgdir + (unsigned int) PDX(va);
//PTE_ADDR used for both pte and pde
if (*pd & PTE_P)
return (pte_t*) KADDR(PTE_ADDR(*pd)) + (unsigned)PTX(va);
// if page doesn't exist
if (create == 0) return NULL;
struct PageInfo* newpt = page_alloc(1);
if (newpt == NULL) return NULL;
newpt -> pp_ref = 1;
*pd = page2pa(newpt) | PTE_P | PTE_U | PTE_W;
return (pte_t*)page2kva(newpt) + (unsigned) PTX(va);
}
开发者ID:DoraXingyu,项目名称:JosLab_2015,代码行数:38,代码来源:pmap.c
示例15: pgdir_walk
// Given 'pgdir', a pointer to a page directory, pgdir_walk returns
// a pointer to the page table entry (PTE) for linear address 'va'.
// This requires walking the two-level page table structure.
//
// The relevant page table page might not exist yet.
// If this is true, and create == false, then pgdir_walk returns NULL.
// Otherwise, pgdir_walk allocates a new page table page with page_alloc.
// - If the allocation fails, pgdir_walk returns NULL.
// - Otherwise, the new page's reference count is incremented,
// the page is cleared,
// and pgdir_walk returns a pointer into the new page table page.
//
// Hint 1: you can turn a Page * into the physical address of the
// page it refers to with page2pa() from kern/pmap.h.
//
// Hint 2: the x86 MMU checks permission bits in both the page directory
// and the page table, so it's safe to leave permissions in the page
// more permissive than strictly necessary.
//
// Hint 3: look at inc/mmu.h for useful macros that mainipulate page
// table and page directory entries.
//
pte_t *
pgdir_walk(pde_t *pgdir, const void *va, int create)
{
pde_t *pde;
pte_t *pgtab;
struct PageInfo *pp;
pde = &pgdir[PDX(va)];
if (*pde & PTE_P) {
// KADDR(pa) : get the corresponding va of this pa.
// ( reversed va->pa mapping )
// understanding why we need KADDR and PADDR is very important :
// note :
// 1. dereference, uintptr_t, physaddr_t
// 2. the kernel, like any other software, cannot bypass virtual
// memory translation and thus cannot directly load and store
// to physical addresses.
// 3. the kernel has set up some page table that has the direct
// mapping of va -> pa.
// 4. all pointers in c are virtual address.
// read this :
// http://pdos.csail.mit.edu/6.828/2012/labs/lab2/#Virtual--Linear--and-Physical-Addresses
pgtab = (pte_t*)KADDR(PTE_ADDR(*pde));
} else {
if (!create || (pp = page_alloc(ALLOC_ZERO)) == 0)
return 0;
pp->pp_ref = 1;
pgtab = (pte_t*)KADDR(page2pa(pp));
*pde = PADDR(pgtab) | PTE_P | PTE_W | PTE_U;
}
return &pgtab[PTX(va)];
}
开发者ID:cookiebus,项目名称:6.828_labs_2012,代码行数:54,代码来源:pmap.c
示例16: pgdir_walk
// Given 'pgdir', a pointer to a page directory, pgdir_walk returns
// a pointer to the page table entry (PTE) for linear address 'va'.
// This requires walking the two-level page table structure.
//
// The relevant page table page might not exist yet.
// If this is true, and create == false, then pgdir_walk returns NULL.
// Otherwise, pgdir_walk allocates a new page table page with page_alloc.
// - If the allocation fails, pgdir_walk returns NULL.
// - Otherwise, the new page's reference count is incremented,
// the page is cleared,
// and pgdir_walk returns a pointer into the new page table page.
//
// Hint: Check out page2pa() and page2kva() in kern/pmap.h.
//
// Hint 2: the x86 MMU checks permission bits in both the page directory
// and the page table.
pte_t *
pgdir_walk(pde_t *pgdir, uintptr_t va, bool create)
{
// Use the page directory index to look up the page table entry
physaddr_t page_table = pgdir[PDX(va)];
// Check whether the entry is present
if (!(page_table & PTE_P)) {
// The page table doesn't exist yet
if (!create) return NULL;
// Try creating a new page table
Page *page = page_alloc();
// If a page couldn't be allocated, return NULL
if (page == NULL) return NULL;
page_table = (physaddr_t) page2pa(page);
// Should be 4KB aligned
assert(PGALIGNED(page_table));
// Increment the new page's reference count
page->pp_ref++;
// Clear the page
memset((void *)KADDR(page_table), 0, PGSIZE);
// Set the present bit of this entry
page_table = page_table | PTE_W | PTE_U | PTE_P;
// Install it in the directory
pgdir[PDX(va)] = page_table;
}
// Page table address is the top 20 bits of the entry + 12 zeros
return (pte_t *) &((pte_t *) KADDR(PTE_ADDR(page_table)))[PTX(va)];
}
开发者ID:aaandrewww,项目名称:authcontrol,代码行数:46,代码来源:pmap.c
示例17: pgdir_walk
// Given 'pgdir', a pointer to a page directory, pgdir_walk returns
// a pointer to the page table entry (PTE) for linear address 'va'.
// This requires walking the two-level page table structure.
//
// The relevant page table page might not exist yet.
// If this is true, and create == false, then pgdir_walk returns NULL.
// Otherwise, pgdir_walk allocates a new page table page with page_alloc.
// - If the allocation fails, pgdir_walk returns NULL.
// - Otherwise, the new page's reference count is incremented,
// the page is cleared,
// and pgdir_walk returns a pointer into the new page table page.
//
// Hint 1: you can turn a Page * into the physical address of the
// page it refers to with page2pa() from kern/pmap.h.
//
// Hint 2: the x86 MMU checks permission bits in both the page directory
// and the page table, so it's safe to leave permissions in the page
// more permissive than strictly necessary.
//
// Hint 3: look at inc/mmu.h for useful macros that mainipulate page
// table and page directory entries.
//
pte_t *
pgdir_walk(pde_t *pgdir, const void *va, int create)
{
// Fill this function in
physaddr_t pt_addr;
struct PageInfo * new_page;
pte_t * pagetable;
assert(pgdir != NULL);
if ((pgdir[PDX(va)] & PTE_P) == 0) {
if (!create) {
return NULL;
}
new_page = page_alloc(ALLOC_ZERO);
if (new_page == NULL) {
return NULL;
}
new_page->pp_ref++;
pgdir[PDX(va)] = page2pa(new_page) | PTE_U | PTE_W | PTE_P;
}
pt_addr = PTE_ADDR(pgdir[PDX(va)]);
pagetable = KADDR(pt_addr);
return &pagetable[PTX(va)];
}
开发者ID:delili,项目名称:jos-lab2,代码行数:52,代码来源:pmap.c
示例18: get_pte
pte_t *
get_pte(pgd_t *pgdir, uintptr_t la, bool create) {
#if PTXSHIFT == PMXSHIFT
return get_pmd(pgdir, la, create);
#else /* PTXSHIFT == PMXSHIFT */
pmd_t *pmdp;
if ((pmdp = get_pmd(pgdir, la, create)) == NULL) {
return NULL;
}
if (! ptep_present(pmdp)) {
struct Page *page;
if (!create || (page = alloc_page()) == NULL) {
return NULL;
}
set_page_ref(page, 1);
uintptr_t pa = page2pa(page);
memset(KADDR(pa), 0, PGSIZE);
#ifdef ARCH_ARM
pdep_map(pmdp, pa);
#else
ptep_map(pmdp, pa);
#endif
#ifndef ARCH_ARM
ptep_set_u_write(pmdp);
ptep_set_accessed(pmdp);
ptep_set_dirty(pmdp);
#else
#warning ARM9 PDE does not have access field
#endif
}
return &((pte_t *)KADDR(PMD_ADDR(*pmdp)))[PTX(la)];
#endif /* PTXSHIFT == PMXSHIFT */
}
开发者ID:chyyuu,项目名称:ucore-arch-arm,代码行数:33,代码来源:pmm.c
示例19: pgdir_walk
// Given 'pgdir', a pointer to a page directory, pgdir_walk returns
// a pointer to the page table entry (PTE) for linear address 'va'.
// This requires walking the two-level page table structure.
//
// The relevant page table page might not exist yet.
// If this is true, and create == false, then pgdir_walk returns NULL.
// Otherwise, pgdir_walk allocates a new page table page with page_alloc.
// - If the allocation fails, pgdir_walk returns NULL.
// - Otherwise, the new page's reference count is incremented,
// the page is cleared,
// and pgdir_walk returns a pointer into the new page table page.
//
// Hint 1: you can turn a Page * into the physical address of the
// page it refers to with page2pa() from kern/pmap.h.
//
// Hint 2: the x86 MMU checks permission bits in both the page directory
// and the page table, so it's safe to leave permissions in the page
// more permissive than strictly necessary.
//
// Hint 3: look at inc/mmu.h for useful macros that mainipulate page
// table and page directory entries.
//
pte_t *
pgdir_walk(pde_t *pgdir, const void *va, int create)
{
// Fill this function in
pte_t* p1 = 0;
pte_t* p2 = 0;
pte_t* result;
struct Page* pg;
p1=pgdir + PDX(va);
if(!((*p1) & PTE_P))
{
if(!create)
return 0;
if( !(pg=page_alloc(ALLOC_ZERO)) )
{
return 0;
}
pg->pp_ref++;
*p1=PTE_P | PTE_U | PTE_W | page2pa(pg) ;
p2=KADDR( PTE_ADDR(*p1) );
}
else{
p2=KADDR( PTE_ADDR(*p1) );
}
result=p2+PTX(va);
return result;
}
开发者ID:yahu,项目名称:JOS,代码行数:54,代码来源:pmap.c
示例20: mmumapcpu0
void
mmumapcpu0(void)
{
ulong *pdb, *pte, va, pa, pdbx;
if(strstr(xenstart->magic, "x86_32p"))
paemode = 1;
hypervisor_virt_start = paemode ? 0xF5800000 : 0xFC000000;
patomfn = (ulong*)xenstart->mfn_list;
matopfn = (ulong*)hypervisor_virt_start;
/* Xen bug ? can't touch top entry in PDPT */
if(paemode)
hypervisor_virt_start = 0xC0000000;
/*
* map CPU0MACH at MACHADDR.
* When called the pagedir and page table exist, we just
* need to fill in a page table entry.
*/
pdb = (ulong*)xenstart->pt_base;
va = MACHADDR;
pa = PADDR(CPU0MACH) | PTEVALID|PTEWRITE;
pdbx = PDX(va);
pdb = PDB(pdb, va);
pte = KADDR(MAPPN(pdb[pdbx]));
xenupdate(&pte[PTX(va)], pa);
}
开发者ID:Nurb432,项目名称:plan9front,代码行数:27,代码来源:mmu.c
注:本文中的PTX函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论