__forceinline static void SetPage( __in const void* addr, __in size_t size ) { const BYTE* end_addr = reinterpret_cast<const BYTE*>(PAGE_ALIGN((ULONG_PTR)addr + size + PAGE_SIZE)); for (addr = reinterpret_cast<const BYTE*>(addr); addr < end_addr; addr = reinterpret_cast<const void*>((ULONG_PTR)addr + PAGE_SIZE)) { CMMU mmu(addr); PAGE_TABLE_ENTRY pte; if (mmu.GetPTE(pte)) { switch (FLAG) { case Write: pte.Write = VAL; break; case Exec: pte.NoExecute = !VAL; break; case NoAccess: pte.Valid = !VAL; break; default: break; } mmu.SetPTE(pte); } } }
/* input block, this is per port */ void input_block(int port_number) { ETHERNET_FRAME buf; //an abstract type to store a received Ethernet frame int port_mask; int priority; int address; while(1) { if( receive(&buf,port_number) == TRUE ) { // ask Routing Table Unit rtu(&buf, &port_mask, &priority); //acquire address of the first page address = mmu(); //store in memory fbm_memory[address].buf = buf; // forward a pointer to the frame to all the appropriate ports // waits until all the appropriate ports read the data arbiter(port_mask, priority, address); } } }
void loader() { int p, i; int currentFrame; int currentPage = 0; int memoryLoc; // Place user program pages into main memory frames for (p = userArray[queueArray[currentPriority][0]->pid].memoryLocation; p < (userArray[queueArray[currentPriority][0]->pid].progLength + userArray[queueArray[currentPriority][0]->pid].memoryLocation);) { currentFrame = rand() % 64; memoryLoc = currentFrame * MEMORY_LENGTH; if (currentPage == 0) { queueArray[currentPriority][0]->pCounter = memoryLoc; } if (usedFrames[currentFrame] == 0) { for (i = 0; i < MEMORY_LENGTH; i++, p++) { mainMemory[memoryLoc + i] = disk[p]; memoryPrint[memoryLoc + i] = queueArray[currentPriority][0]->pid; diskPrint[p] = 1; } usedFrames[currentFrame] = 1; mmu(currentPage, currentFrame); currentPage++; } } }
static bool IsAccessed( __in const void* addr ) { CMMU mmu(addr); PAGE_TABLE_ENTRY pte; return (mmu.GetPTE(pte) && pte.Accessed); }
static bool IsWriteable( __in const void* addr ) { CMMU mmu(addr); PAGE_TABLE_ENTRY pte; return (mmu.GetPTE(pte) && pte.Write); }
// responsible for the machine languare interpretation and execution void interpreter() { printf("\n"); if (queueArray[currentPriority][0]->pid > 0) printf("User %d Running...\n", queueArray[currentPriority][0]->pid); while (haltFlag == false && currentTick < TICKS_PER_USER) { Fetch(); Decode(); mmu(-1, -1); Execute(); if (queueArray[currentPriority][0]->frameTick % MEMORY_LENGTH == 0) { queueArray[currentPriority][0]->pageTick++; queueArray[currentPriority][0]->pCounter = userArray[queueArray[currentPriority][0]->pid].pageTable[queueArray[currentPriority][0]->pageTick] * MEMORY_LENGTH; PC = queueArray[currentPriority][0]->pCounter; } } if (haltFlag == true) { queueArray[currentPriority][0]->isComplete = true; dumpPageTable(); mmu(-2, -2); queueArray[currentPriority][0]->isRunning = false; } else { queueArray[currentPriority][0]->pCounter = PC; queueArray[currentPriority][0]->processCC = CC; CC = 0x0000; int i = 0; for (i; i < MAX_REGISTER; i++) queueArray[currentPriority][0]->processRegisters[i] = Registers[i]; Registers[i] = 0x0000; } haltFlag = false; // reset halt flag for subsequent program runs }
// (This code was copied from EditPolyObj::EpfnCollapse.) bool VWeldMod::WeldShortPolyEdges (MNMesh & mesh, float thresh, DWORD flag) { // In order to collapse vertices, we turn them into edge selections, // where the edges are shorter than the weld threshold. bool canWeld = false; mesh.ClearEFlags (flag); float threshSq = thresh*thresh; for (int i=0; i<mesh.nume; i++) { if (mesh.e[i].GetFlag (MN_DEAD)) continue; if (!mesh.v[mesh.e[i].v1].GetFlag (flag)) continue; if (!mesh.v[mesh.e[i].v2].GetFlag (flag)) continue; if (LengthSquared (mesh.P(mesh.e[i].v1) - mesh.P(mesh.e[i].v2)) > threshSq) continue; mesh.e[i].SetFlag (flag); canWeld = true; } if (!canWeld) return false; MNMeshUtilities mmu(&mesh); return mmu.CollapseEdges (MN_USER); }