本文整理汇总了C++中PTX函数的典型用法代码示例。如果您正苦于以下问题:C++ PTX函数的具体用法?C++ PTX怎么用?C++ PTX使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PTX函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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)]));
}
}
示例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);
}
示例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);
}
示例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;
}
示例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)]);
}
}
示例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)];
}
示例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);
}
}
}
示例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);
}
示例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;
}
示例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)];
}
示例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);
}
}
示例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)]);
}
示例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);
}
示例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)];
}