예제 #1
0
void CALLING_CONVENTION CX86Scheduler::initialise()
{
	if (m_bInitialised)
		return;
	//Create the kernel's process
	m_lock.acquireSpinlock();

	PPROCESS kernelproc = new PROCESS;
	if (!kernelproc)
		goto end;
	kernelproc->addrspace = READ_CR3();
	kernelproc->pid = KERNEL_PID;

	m_nextpid = KERNEL_PID + 1;

	kernelproc->priority = PROCESS_PRIORITY_SYSTEM_REALTIME;		//The highest priority
	kernelproc->name = L"ChaiOS System";
	PTHREAD kernelthread = new THREAD;
	if (!kernelthread)
		goto end;
	memset(kernelthread->context, 0, sizeof(kernelthread->context));	//Clear context information. This will be filled out
	kernelthread->kstack = (size_t)getMemoryManager()->getVMemMngr()->allocateSinglePage(getMemoryManager()->getVMemMngr()->getDefaultAttributes(true));		//This stack should never be used, it is a kernel process.
	kernelthread->parentpid = kernelproc->pid;
	kernelthread->parent = kernelproc;
	kernelthread->tid = (size_t)kernelthread;	//For simplicity, thread IDs are pointers to their thread structure
	kernelthread->waitcount = 0;				//This thread is running
	
	//Register thread and process
	kernelproc->threadlist.insertToTail(kernelthread);
	m_processList.insertToTail(kernelproc);
	m_runningList.insertToTail(kernelthread);

	m_numcpus = getHal()->getMultiprocessorIrq()->getNumCPUs();
	m_execProcess = new PTHREAD[m_numcpus];
	memset(m_execProcess, 0, m_numcpus*sizeof(PTHREAD));
	m_execProcess[getHal()->getMultiprocessorIrq()->getCurrentCpuNum()] = kernelthread;

	m_bInitialised = true;
end:
	m_lock.releaseSpinlock();
}
예제 #2
0
파일: paging.c 프로젝트: jpdantur/SO2
// FAULT HANDLER
void PageFaultHandler(uint64 error, uint64 cr2) {
interruptionsStateBackup = SetInterruptions(FALSE);
backupCR3 = READ_CR3();

  Offsets* off 	= (Offsets*) malloc(sizeof(Offsets));
  off->phyOff 	= cr2      & 0x0000000000000FFF;
  off->L1    	= ((cr2    & 0x00000000001FF000) >> 12) & 0x00000000000001FF;
  off->L2    	= ((cr2    & 0x000000003FE00000) >> 21) & 0x00000000000001FF;
  off->L3    	= ((cr2    & 0x0000007FC0000000) >> 30) & 0x00000000000001FF;
  off->L4    	= ((cr2	   & 0x0000FF8000000000) >> 39) & 0x00000000000001FF;

  if (cr2 < (22 * 0x100000)) {
    // Proccess requested memory ourside stack bounds
    while(1);
  }
  else if (cr2 >= (22 * 0x100000) && cr2 < (30 * 0x100000)) {
    // Proccess needs memory in stack
    switch_u2k();
    WRITE_CR3(identityCR3);
    AddPage(backupCR3, off, 1, 1);
    WRITE_CR3(backupCR3);
    switch_k2u();
  }
  else if (cr2 >= (30 * 0x100000) && cr2 < (32 * 0x100000)) {
  	// Proccess needs memory in heap
  	switch_u2k();
  	WRITE_CR3(identityCR3);
    AddPage(backupCR3, off, 1, 1);
    WRITE_CR3(backupCR3);
    switch_k2u();

  }
  else if (cr2 >= (32 * 0x100000)) {
    // Proccess requested memory ourside heap bounds
    while(1);
  }

  SetInterruptions(interruptionsStateBackup);
  return;
}
예제 #3
0
파일: paging.c 프로젝트: jpdantur/SO2
void BackUpState(){
	interruptionsStateBackup = SetInterruptions(FALSE);
	backupCR3 = READ_CR3();
	WRITE_CR3(identityCR3);
}