void ExprRep::reduceToZero() { appValue() = CORE_REAL_ZERO; appComputed() = true; flagsComputed() = true; knownPrecision() = CORE_negInfty; #ifdef CORE_DEBUG relPrecision() = EXTLONG_ZERO; absPrecision() = CORE_negInfty; // numNodes() = 0; #endif d_e() = EXTLONG_ONE; visited() = false; sign() = 0; uMSB() = CORE_negInfty; lMSB() = CORE_negInfty; // length() = 0; // fixed? original = 1 measure() = EXTLONG_ZERO; // BFMSS[2,5] bound. u25() = l25() = v2p() = v2m() = v5p() = v5m() = EXTLONG_ZERO; low() = EXTLONG_ONE; // fixed? original = 0 high() = lc() = tc() = EXTLONG_ZERO; if (rationalReduceFlag) { if (ratFlag() > 0) { ratFlag() ++; if (ratValue() == NULL) ratValue() = new BigRat(0); else *(ratValue()) = 0; } else ratFlag() = 1; } }
// Allocate page tables and physical memory to grow process from oldsz to // newsz, which need not be page aligned. Returns new size or 0 on error. int allocuvm(pde_t *pgdir, uint oldsz, uint newsz) { char *mem; uint a; if(newsz >= KERNBASE) return 0; if(newsz < oldsz) return oldsz; a = PGROUNDUP(oldsz); for(; a < newsz; a += PGSIZE){ mem = kalloc(); if(mem == 0){ cprintf("allocuvm out of memory\n"); deallocuvm(pgdir, newsz, oldsz); return 0; } memset(mem, 0, PGSIZE); mappages(pgdir, (char*)a, PGSIZE, v2p(mem), PTE_W|PTE_U); } return newsz; }
bool IsVectorOfImplicationsIdentical(std::vector<FCA::Implication> v1, std::vector<FCA::Implication> v2) { std::vector<std::pair<std::vector<std::string>, std::vector<std::string> > > v1p(v1.size()), v2p(v2.size()); for (size_t i = 0; i < v1.size(); ++i) { v1p[i].first = v1[i].Premise(); v1p[i].second = v1[i].Conclusion(); } for (size_t i = 0; i < v2.size(); ++i) { v2p[i].first = v2[i].Premise(); v2p[i].second = v2[i].Conclusion(); } std::sort(v1p.begin(), v1p.end()); std::sort(v2p.begin(), v2p.end()); for (size_t i = 0; i < v1p.size(); ++i) { std::sort(v1p[i].first.begin(), v1p[i].first.end()); std::sort(v1p[i].second.begin(), v1p[i].second.end()); } for (size_t i = 0; i < v1p.size(); ++i) { std::sort(v2p[i].first.begin(), v2p[i].first.end()); std::sort(v2p[i].second.begin(), v2p[i].second.end()); } return v1p == v2p; }
// Switch h/w page table register to the kernel-only page table, // for when no process is running. void switchkvm(struct cpu *c) { lcr3(v2p(c->kpgdir)); // switch to the kernel page table }
// Switch h/w page table register to the kernel-only page table, // for when no process is running. void switchkvm(void) { lcr3(v2p(kpgdir)); // switch to the kernel page table }
void switchkvm() { lcr3(v2p(kpgmap)); }
void SqrtRep::computeExactFlags() { if (!child->flagsComputed()) child->computeExactFlags(); if (rationalReduceFlag) ratFlag() = -1; sign() = child->sign(); if (sign() < 0) core_error("squareroot is called with negative operand.", __FILE__, __LINE__, true); uMSB() = child->uMSB() / EXTLONG_TWO; lMSB() = child->lMSB() / EXTLONG_TWO; // length() = child->length(); measure() = child->measure(); // BFMSS[2,5] bound. if (child->v2p() + ceilLg5(child->v5p()) + child->u25() >= child->v2m() + ceilLg5(child->v5m()) + child->l25()) { extLong vtilda2 = child->v2p() + child->v2m(); v2p() = vtilda2 / EXTLONG_TWO; v2m() = child->v2m(); extLong vmod2; if (v2p().isInfty()) vmod2 = CORE_INFTY; else vmod2 = vtilda2 - EXTLONG_TWO*v2p(); // == vtilda2 % 2 extLong vtilda5 = child->v5p() + child->v5m(); v5p() = vtilda5 / EXTLONG_TWO; v5m() = child->v5m(); extLong vmod5; if (v5p().isInfty()) vmod5 = CORE_INFTY; else vmod5 = vtilda5 - EXTLONG_TWO*v5p(); // == vtilda5 % 2 u25() = (child->u25() + child->l25() + vmod2 + ceilLg5(vmod5) + EXTLONG_ONE) / EXTLONG_TWO; l25() = child->l25(); } else { extLong vtilda2 = child->v2p() + child->v2m(); v2p() = child->v2p(); v2m() = vtilda2 / EXTLONG_TWO; extLong vmod2; if (v2m().isInfty()) vmod2 = CORE_INFTY; else vmod2 = vtilda2 - EXTLONG_TWO*v2m(); // == vtilda2 % 2 extLong vtilda5 = child->v5p() + child->v5m(); v5p() = child->v5p(); v5m() = vtilda5 / EXTLONG_TWO; u25() = child->u25(); extLong vmod5; if (v5m().isInfty()) vmod5 = CORE_INFTY; else vmod5 = vtilda5 - EXTLONG_TWO*v5m(); // == vtilda5 % 2 l25() = (child->u25() + child->l25() + vmod2 + ceilLg5(vmod5) + EXTLONG_ONE) / EXTLONG_TWO; } high() = (child->high() +EXTLONG_ONE)/EXTLONG_TWO; low() = child->low() / EXTLONG_TWO; lc() = child->lc(); tc() = child->tc(); flagsComputed() = true; }// SqrtRep::computeExactFlags
// This only copies the current information of the argument e to // *this ExprRep. void ExprRep::reduceTo(const ExprRep *e) { if (e->appComputed()) { appValue() = e->appValue(); appComputed() = true; flagsComputed() = true; knownPrecision() = e->knownPrecision(); #ifdef CORE_DEBUG relPrecision() = e->relPrecision(); absPrecision() = e->absPrecision(); numNodes() = e->numNodes(); #endif } d_e() = e->d_e(); //visited() = e->visited(); sign() = e->sign(); uMSB() = e->uMSB(); lMSB() = e->lMSB(); // length() = e->length(); // fixed? original = 1 measure() = e->measure(); // BFMSS[2,5] bound. u25() = e->u25(); l25() = e->l25(); v2p() = e->v2p(); v2m() = e->v2m(); v5p() = e->v5p(); v5m() = e->v5m(); high() = e->high(); low() = e->low(); // fixed? original = 0 lc() = e->lc(); tc() = e->tc(); // Chee (Mar 23, 2004), Notes on ratFlag(): // =============================================================== // For more information on the use of this flag, see progs/pentagon. // This is an integer valued member of the NodeInfo class. // Its value is used to determine whether // we can ``reduce'' an Expression to a single node containing // a BigRat value. This reduction is done if the global variable // rationalReduceFlag=true. The default value is false. // This is the intepretation of ratFlag: // ratFlag < 0 means irrational // ratFlag = 0 means not initialized // ratFlag > 0 means rational // Currently, ratFlag>0 is an upper bound on the size of the expression, // since we recursively compute // ratFlag(v) = ratFlag(v.lchild)+ratFlag(v.rchild) + 1. // PROPOSAL: if ratFlag() > RAT_REDUCE_THRESHHOLD // then we automatically do a reduction. We must determine // an empirical value for RAT_REDUCE_THRESHOLD if (rationalReduceFlag) { ratFlag() = e->ratFlag(); if (e->ratFlag() > 0 && e->ratValue() != NULL) { ratFlag() ++; if (ratValue() == NULL) ratValue() = new BigRat(*(e->ratValue())); else *(ratValue()) = *(e->ratValue()); } else ratFlag() = -1; } }
// Computes the root bit bound of the expression. // In effect, computeBound() returns the current value of low. extLong ExprRep::computeBound() { extLong measureBd = measure(); // extLong cauchyBd = length(); extLong ourBd = (d_e() - EXTLONG_ONE) * high() + lc(); // BFMSS[2,5] bound. extLong bfmsskBd; if (v2p().isInfty() || v2m().isInfty()) bfmsskBd = CORE_INFTY; else bfmsskBd = l25() + u25() * (d_e() - EXTLONG_ONE) - v2() - ceilLg5(v5()); // since we might compute \infty - \infty for this bound if (bfmsskBd.isNaN()) bfmsskBd = CORE_INFTY; extLong bd = core_min(measureBd, // core_min(cauchyBd, core_min(bfmsskBd, ourBd)); #ifdef CORE_SHOW_BOUNDS std::cout << "Bounds (" << measureBd << "," << bfmsskBd << ", " << ourBd << "), "; std::cout << "MIN = " << bd << std::endl; std::cout << "d_e= " << d_e() << std::endl; #endif #ifdef CORE_DEBUG_BOUND // Some statistics about which one is/are the winner[s]. computeBoundCallsCounter++; int number_of_winners = 0; std::cerr << " New contest " << std::endl; if (bd == bfmsskBd) { BFMSS_counter++; number_of_winners++; std::cerr << " BFMSS is the winner " << std::endl; } if (bd == measureBd) { Measure_counter++; number_of_winners++; std::cerr << " measureBd is the winner " << std::endl; } /* if (bd == cauchyBd) { Cauchy_counter++; number_of_winners++; std::cerr << " cauchyBd is the winner " << std::endl; } */ if (bd == ourBd) { LiYap_counter++; number_of_winners++; std::cerr << " ourBd is the winner " << std::endl; } assert(number_of_winners >= 1); if (number_of_winners == 1) { if (bd == bfmsskBd) { BFMSS_only_counter++; std::cerr << " BFMSSBd is the only winner " << std::endl; } else if (bd == measureBd) { Measure_only_counter++; std::cerr << " measureBd is the only winner " << std::endl; } /* else if (bd == cauchyBd) { Cauchy_only_counter++; std::cerr << " cauchyBd is the only winner " << std::endl; } */ else if (bd == ourBd) { LiYap_only_counter++; std::cerr << " ourBd is the only winner " << std::endl; } } #endif return bd; }//computeBound()
void switchkvm(void) { lcr3(v2p(kpml4)); }
//PAGEBREAK: 41 void trap(struct trapframe *tf) { if(tf->trapno == T_SYSCALL){ if(proc->killed) exit(); proc->tf = tf; syscall(); if(proc->killed) exit(); return; } // Lazy page allocation if(tf->trapno == T_PGFLT) { uint a = PGROUNDDOWN(rcr2()); // round down faulting VA to page boundary char *mem; mem = kalloc(); memset(mem, 0, PGSIZE); //cprintf("Lazy page allocation at 0x%x\n", a); mappages(proc->pgdir, (char*)a, PGSIZE, v2p(mem), PTE_W|PTE_U); return; } switch(tf->trapno){ case T_IRQ0 + IRQ_TIMER: if(cpu->id == 0){ acquire(&tickslock); ticks++; if(proc && (tf->cs & 3) == 3){ proc->alarmleft--; if(proc->alarmleft == 0){ proc->alarmleft = proc->alarmticks; tf->esp -= 4; *(uint*)tf->esp = tf->eip; // XXX: security flaw, need check before tf->eip = (uint) proc->alarmhandler; } } wakeup(&ticks); release(&tickslock); } lapiceoi(); break; case T_IRQ0 + IRQ_IDE: ideintr(); lapiceoi(); break; case T_IRQ0 + IRQ_IDE+1: // Bochs generates spurious IDE1 interrupts. break; case T_IRQ0 + IRQ_KBD: kbdintr(); lapiceoi(); break; case T_IRQ0 + IRQ_COM1: uartintr(); lapiceoi(); break; case T_IRQ0 + 7: case T_IRQ0 + IRQ_SPURIOUS: cprintf("cpu%d: spurious interrupt at %x:%x\n", cpu->id, tf->cs, tf->eip); lapiceoi(); break; //PAGEBREAK: 13 default: if(proc == 0 || (tf->cs&3) == 0){ // In kernel, it must be our mistake. cprintf("unexpected trap %d from cpu %d eip %x (cr2=0x%x)\n", tf->trapno, cpu->id, tf->eip, rcr2()); panic("trap"); } // In user space, assume process misbehaved. cprintf("pid %d %s: trap %d err %d on cpu %d " "eip 0x%x addr 0x%x--kill proc\n", proc->pid, proc->name, tf->trapno, tf->err, cpu->id, tf->eip, rcr2()); proc->killed = 1; } // Force process exit if it has been killed and is in user space. // (If it is still executing in the kernel, let it keep running // until it gets to the regular system call return.) if(proc && proc->killed && (tf->cs&3) == DPL_USER) exit(); // Force process to give up CPU on clock tick. // If interrupts were on while locks held, would need to check nlock. if(proc && proc->state == RUNNING && tf->trapno == T_IRQ0+IRQ_TIMER) yield(); // Check if the process has been killed since we yielded if(proc && proc->killed && (tf->cs&3) == DPL_USER) exit(); }
//PAGEBREAK: 41 void trap(struct trapframe *tf) { if(tf->trapno == T_SYSCALL){ if(proc->killed) exit(); proc->tf = tf; syscall(); if(proc->killed) exit(); return; } switch(tf->trapno){ case T_IRQ0 + IRQ_TIMER: if(cpu->id == 0){ acquire(&tickslock); ticks++; wakeup(&ticks); // We're in user space if(proc && (tf->cs & 3) == DPL_USER) { //is the alarm set? if(proc->alarmticks != 0 && proc->alarmhandler != 0) { proc->alarmticksleft--; if(proc->alarmticksleft == 0) { proc->tf->esp--; *(uint*)proc->tf->esp = proc->tf->eip; proc->tf->eip = (uint)proc->alarmhandler; proc->alarmticksleft = proc->alarmticks; } } } release(&tickslock); } lapiceoi(); break; case T_IRQ0 + IRQ_IDE: ideintr(); lapiceoi(); break; case T_IRQ0 + IRQ_IDE+1: // Bochs generates spurious IDE1 interrupts. break; case T_IRQ0 + IRQ_KBD: kbdintr(); lapiceoi(); break; case T_IRQ0 + IRQ_COM1: uartintr(); lapiceoi(); break; case T_IRQ0 + 7: case T_IRQ0 + IRQ_SPURIOUS: cprintf("cpu%d: spurious interrupt at %x:%x\n", cpu->id, tf->cs, tf->eip); lapiceoi(); break; //PAGEBREAK: 13 default: if(proc == 0 || (tf->cs&3) == 0){ // In kernel, it must be our mistake. cprintf("unexpected trap %d from cpu %d eip %x (cr2=0x%x)\n", tf->trapno, cpu->id, tf->eip, rcr2()); panic("trap"); } // In user space, check whether it is an access to an lazy allocated address if(tf->trapno == T_PGFLT) { char *mem; uint a; a = PGROUNDDOWN(rcr2()); mem = kalloc(); if(mem == 0){ cprintf("allocuvm out of memory\n"); deallocuvm(proc->pgdir, a+PGSIZE, rcr2()); exit(); } memset(mem, 0, PGSIZE); mappages(proc->pgdir, (char*)a, PGSIZE, v2p(mem), PTE_W|PTE_U); } else { //If not, the user program is misbehaving cprintf("pid %d %s: trap %d err %d on cpu %d " "eip 0x%x addr 0x%x--kill proc\n", proc->pid, proc->name, tf->trapno, tf->err, cpu->id, tf->eip, rcr2()); proc->killed = 1; } } // Force process exit if it has been killed and is in user space. // (If it is still executing in the kernel, let it keep running // until it gets to the regular system call return.) if(proc && proc->killed && (tf->cs&3) == DPL_USER) exit(); // Force process to give up CPU on clock tick. // If interrupts were on while locks held, would need to check nlock. if(proc && proc->state == RUNNING && tf->trapno == T_IRQ0+IRQ_TIMER) yield(); // Check if the process has been killed since we yielded if(proc && proc->killed && (tf->cs&3) == DPL_USER) exit(); }
int exec(char *path, char **argv) { char *s, *last; int i, off; uint argc, sz, sp, ustack[3+MAXARG+1]; struct elfhdr elf; struct inode *ip; struct proghdr ph; pde_t *pgdir, *oldpgdir; if((ip = namei(path)) == 0) return -1; ilock(ip); pgdir = 0; // Check ELF header if(readi(ip, (char*)&elf, 0, sizeof(elf)) < sizeof(elf)) goto bad; if(elf.magic != ELF_MAGIC) goto bad; if((pgdir = setupkvm(kalloc)) == 0) goto bad; // Load program into memory. // leave first page inaccessible (to make NULL ref fail) sz = PGSIZE-1; for(i=0, off=elf.phoff; i<elf.phnum; i++, off+=sizeof(ph)){ if(readi(ip, (char*)&ph, off, sizeof(ph)) != sizeof(ph)) goto bad; if(ph.type != ELF_PROG_LOAD) continue; if(ph.memsz < ph.filesz) goto bad; if((sz = allocuvm(pgdir, sz, ph.vaddr + ph.memsz)) == 0) goto bad; if(loaduvm(pgdir, (char*)ph.vaddr, ip, ph.off, ph.filesz) < 0) goto bad; } iunlockput(ip); ip = 0; // Allocate two pages at the next page boundary. // Make the first inaccessible. Use the second as the user stack. sz = PGROUNDUP(sz); if((sz = allocuvm(pgdir, sz, sz + 2*PGSIZE)) == 0) goto bad; clearpteu(pgdir, (char*)(sz - 2*PGSIZE)); sp = sz; // Push argument strings, prepare rest of stack in ustack. for(argc = 0; argv[argc]; argc++) { if(argc >= MAXARG) goto bad; sp = (sp - (strlen(argv[argc]) + 1)) & ~3; if(copyout(pgdir, sp, argv[argc], strlen(argv[argc]) + 1) < 0) goto bad; ustack[3+argc] = sp; } ustack[3+argc] = 0; ustack[0] = 0xffffffff; // fake return PC ustack[1] = argc; ustack[2] = sp - (argc+1)*4; // argv pointer sp -= (3+argc+1) * 4; if(copyout(pgdir, sp, ustack, (3+argc+1)*4) < 0) goto bad; // Save program name for debugging. for(last=s=path; *s; s++) if(*s == '/') last = s+1; safestrcpy(proc->name, last, sizeof(proc->name)); // hook up the old shared memory to the new addr space // (no need to change refcount, because the old ref goes away with // this exec, so it's +1 then -1 => 0 change if (proc->shared) { extern void mappages(pde_t *pgdir, void *va, uint size, uint pa, int perm); mappages(pgdir, (char *)SHARED_V, PGSIZE, v2p(proc->shared->page), PTE_W|PTE_U); } // Commit to the user image. oldpgdir = proc->pgdir; proc->pgdir = pgdir; proc->sz = sz; proc->tf->eip = elf.entry; // main proc->tf->esp = sp; switchuvm(proc); freevm(oldpgdir); return 0; bad: if(pgdir) freevm(pgdir); if(ip) iunlockput(ip); return -1; }
bool RenderableObject::IsInstance(RenderableObject& model) { // First test is the number of indices if (m_indices_size != model.m_indices_size) return false; // Second test is the number of buffers if (m_buffers.size() != model.m_buffers.size()) return false; // Third test buffers size for (BufferMap::const_iterator it = m_buffers.begin(); it != m_buffers.end(); it++) { BufferMap::const_iterator it2 = model.m_buffers.find(it->first); if (it2 == model.m_buffers.end()) return false; if (it2->second.dimension != it->second.dimension) return false; if (it2->second.size != it->second.size) return false; } // Last step : Check buffer contents // * Check if they needs to compute the transformation bool needTransformation = false; Math::CMatrix4 transformationMatrix; if (m_buffers.find(VERTEX_ATTRIBUT) != m_buffers.end() && m_buffers[VERTEX_ATTRIBUT].size >= 11) { Logger::Log() << "[INFO] Try to find the transformations ... \n"; RenderableBuffer b1 = m_buffers[VERTEX_ATTRIBUT]; RenderableBuffer b2 = model.m_buffers[VERTEX_ATTRIBUT]; if (b1.buffer[0] != b2.buffer[0]) { needTransformation = true; // Frist matrix Math::TVector3F v1(b1.buffer[0], b1.buffer[1], b1.buffer[2]); Math::TVector3F v2(b1.buffer[3], b1.buffer[4], b1.buffer[5]); Math::TVector3F v3(b1.buffer[6], b1.buffer[7], b1.buffer[8]); Math::TVector3F v4 = v1 + ((v2 - v1) ^ (v3 - v1)); Math::CMatrix4 t1(v1.x, v2.x, v3.x, v4.x, v1.y, v2.y, v3.y, v4.y, v1.z, v2.z, v3.z, v4.z, 1, 1, 1, 1); // second matrix Math::TVector3F v1p(b2.buffer[0], b2.buffer[1], b2.buffer[2]); Math::TVector3F v2p(b2.buffer[3], b2.buffer[4], b2.buffer[5]); Math::TVector3F v3p(b2.buffer[6], b2.buffer[7], b2.buffer[8]); Math::TVector3F v4p = v1p + ((v2p - v1p) ^ (v3p - v1p)); Math::CMatrix4 t2(v1p.x, v2p.x, v3p.x, v4p.x, v1p.y, v2p.y, v3p.y, v4p.y, v1p.z, v2p.z, v3p.z, v4p.z, 1, 1, 1, 1); transformationMatrix = t1.Inverse() * t2; Logger::Log() << "[INFO] Transform matrice : \n" << transformationMatrix; } } for (BufferMap::const_iterator it = m_buffers.begin(); it != m_buffers.end(); it++) { BufferMap::const_iterator it2 = model.m_buffers.find(it->first); Logger::Log() << "[INFO] INSTANCE : " << it->first << " buffer check instance ... \n"; for (int i = 0; i < it->second.size; i++) { if (!needTransformation) { if (it->second.buffer[i] != it2->second.buffer[i]) { Logger::Log() << "[INFO] Buffer difference detected : " << i << " ( " << it->second.buffer[i] << " != " << it2->second.buffer[i] << " )\n"; return false; } } else { if (it->first == VERTEX_ATTRIBUT || it->first == NORMAL_ATTRIBUT || it->first == TANGENT_ATTRIBUT || it->first == BITANGENT_ATTRIBUT) { // Construct the Vector Math::TVector4F v1(it->second.buffer[i], it->second.buffer[i + 1], it->second.buffer[i + 2], 1.0); Math::TVector4F v2(it2->second.buffer[i], it2->second.buffer[i + 1], it2->second.buffer[i + 2], 1.0); Math::TVector4F vTrans = transformationMatrix.Transform(v1); vTrans /= vTrans.w; if (v2 != vTrans) { Logger::Log() << "[INFO] Buffer difference detected : " << i << " ( " << v2 << " != " << vTrans << " )\n"; return false; } // Must add two steps i += 2; } else { // XXX: Somes copy from other tests if (it->second.buffer[i] != it2->second.buffer[i]) { Logger::Log() << "[INFO] Buffer difference detected : " << i << " ( " << it->second.buffer[i] << " != " << it2->second.buffer[i] << " )\n"; return false; } } } } } // All tests is Ok so Model is an instance return true; }
void mmuWriteByte(Word vAddr, Byte data, Bool userMode) { memoryWriteByte(v2p(vAddr, userMode, true, MMU_ACCS_BYTE), data); }
Byte mmuReadByte(Word vAddr, Bool userMode) { return memoryReadByte(v2p(vAddr, userMode, false, MMU_ACCS_BYTE)); }