亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? system.cpp

?? 自己動(dòng)手寫操作系統(tǒng)源代碼,不可多得的代碼
?? CPP
?? 第 1 頁 / 共 2 頁
字號(hào):
//***********************************************************************/
//    Author                    : Garry
//    Original Date             : Nov,06 2004
//    Module Name               : system.cpp
//    Module Funciton           : 
//                                This module countains system mechanism releated objects's
//                                implementation..
//                                Including the following aspect:
//                                1. Interrupt object and interrupt management code;
//                                2. Timer object and timer management code;
//                                3. System level parameters management coee,such as
//                                   physical memory,system time,etc;
//                                4. Other system mechanism releated objects.
//
//                                ************
//                                This file is one of the most important file of Hello China.
//                                ************
//    Last modified Author      :
//    Last modified Date        :
//    Last modified Content     :
//                                1.
//                                2.
//    Lines number              :
//***********************************************************************/

#ifndef __STDAFX_H__
#include "..\INCLUDE\StdAfx.h"
#endif

__PERF_RECORDER  TimerIntPr = {
	U64_ZERO,
	U64_ZERO,
	U64_ZERO,
	U64_ZERO};                  //Performance recorder object used to mesure
                                //the performance of timer interrupt.

//
//TimerInterruptHandler routine.
//The following routine is the most CRITICAL routine of kernel of Hello China.
//The routine does the following:
// 1. Schedule timer object;
// 2. Update the system level variables,such as dwClockTickCounter;
// 3. Schedule kernel thread(s).
//

static BOOL TimerInterruptHandler(LPVOID lpEsp,LPVOID)
{
	DWORD                     dwPriority        = 0L;
	__TIMER_OBJECT*           lpTimerObject     = 0L;
	__KERNEL_THREAD_MESSAGE   Msg                   ;
	__PRIORITY_QUEUE*         lpTimerQueue      = NULL;
	__PRIORITY_QUEUE*         lpSleepingQueue   = NULL;
	__KERNEL_THREAD_OBJECT*   lpKernelThread    = NULL;
	DWORD                     dwFlags           = 0L;

	if(NULL == lpEsp)    //Parameter check.
		return TRUE;

	if(System.dwClockTickCounter == System.dwNextTimerTick)     //Should schedule timer.
	{
		lpTimerQueue = System.lpTimerQueue;
		lpTimerObject = (__TIMER_OBJECT*)lpTimerQueue->GetHeaderElement(
			(__COMMON_OBJECT*)lpTimerQueue,
			&dwPriority);
		if(NULL == lpTimerObject)
			goto __CONTINUE_1;
		dwPriority = MAX_DWORD_VALUE - dwPriority;
		while(dwPriority <= System.dwNextTimerTick)    //Strictly speaking,the dwPriority
			                                           //variable must EQUAL System.dw-
													   //NextTimerTick,but in the implement-
													   //ing of the current version,there
													   //may be some error exists,so we assume
													   //dwPriority equal or less than dwNext-
													   //TimerTic.
		{
			if(NULL == lpTimerObject->DirectTimerHandler)  //Send a message to the kernel thread.
			{
				Msg.wCommand = KERNEL_MESSAGE_TIMER;
				Msg.dwParam  = lpTimerObject->dwTimerID;
				KernelThreadManager.SendMessage(
					(__COMMON_OBJECT*)lpTimerObject->lpKernelThread,
					&Msg);
				//PrintLine("Send a timer message to kernel thread.");
			}
			else
			{
				lpTimerObject->DirectTimerHandler(
					lpTimerObject->lpHandlerParam);    //Call the associated handler.
			}

			switch(lpTimerObject->dwTimerFlags)
			{
			case TIMER_FLAGS_ONCE:        //Delete the timer object processed just now.
				ObjectManager.DestroyObject(&ObjectManager,
					(__COMMON_OBJECT*)lpTimerObject);
				break;
			case TIMER_FLAGS_ALWAYS:    //Re-insert the timer object into timer queue.
				dwPriority  = lpTimerObject->dwTimeSpan;
				dwPriority /= SYSTEM_TIME_SLICE;
				dwPriority += System.dwClockTickCounter;
				dwPriority  = MAX_DWORD_VALUE - dwPriority;
				lpTimerQueue->InsertIntoQueue((__COMMON_OBJECT*)lpTimerQueue,
					(__COMMON_OBJECT*)lpTimerObject,
					dwPriority);
				break;
			default:
				break;
			}

			lpTimerObject = (__TIMER_OBJECT*)lpTimerQueue->GetHeaderElement(
				(__COMMON_OBJECT*)lpTimerQueue,
				&dwPriority);    //Check another timer object.
			if(NULL == lpTimerObject)
				break;
			dwPriority = MAX_DWORD_VALUE - dwPriority;
		}

		if(NULL == lpTimerObject)  //There is no timer object in queue.
		{
			__ENTER_CRITICAL_SECTION(NULL,dwFlags);
			System.dwNextTimerTick = 0L;
			__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
		}
		else
		{
			__ENTER_CRITICAL_SECTION(NULL,dwFlags);
			System.dwNextTimerTick = dwPriority;    //Update the next timer tick counter.
			__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
			dwPriority = MAX_DWORD_VALUE - dwPriority;
			lpTimerQueue->InsertIntoQueue((__COMMON_OBJECT*)lpTimerQueue,
				(__COMMON_OBJECT*)lpTimerObject,
				dwPriority);
		}
	}

__CONTINUE_1:

	//
	//The following code wakes up all kernel thread(s) whose status is SLEEPING and
	//the time it(then) set is out.
	//
	if(System.dwClockTickCounter == KernelThreadManager.dwNextWakeupTick)  //There must existes
		                                                                   //kernel thread(s) to
																		   //be wake up.
	{
		lpSleepingQueue = KernelThreadManager.lpSleepingQueue;
		lpKernelThread  = (__KERNEL_THREAD_OBJECT*)lpSleepingQueue->GetHeaderElement(
			(__COMMON_OBJECT*)lpSleepingQueue,
			&dwPriority);
		while(lpKernelThread)
		{
			dwPriority = MAX_DWORD_VALUE - dwPriority;  //Now,dwPriority countains the tick
			                                            //counter value.
			if(dwPriority > System.dwClockTickCounter)
				break;    //This kernel thread should not be wake up.
			lpKernelThread->dwThreadStatus = KERNEL_THREAD_STATUS_READY;
			KernelThreadManager.AddReadyKernelThread(
				(__COMMON_OBJECT*)&KernelThreadManager,
				lpKernelThread);  //Insert the waked up kernel thread into ready queue.

			lpKernelThread = (__KERNEL_THREAD_OBJECT*)lpSleepingQueue->GetHeaderElement(
				(__COMMON_OBJECT*)lpSleepingQueue,
				&dwPriority);  //Check next kernel thread in sleeping queue.
		}
		if(NULL == lpKernelThread)
		{
			__ENTER_CRITICAL_SECTION(NULL,dwFlags);
			KernelThreadManager.dwNextWakeupTick = 0L;
			__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
		}
		else
		{
			__ENTER_CRITICAL_SECTION(NULL,dwFlags);
			KernelThreadManager.dwNextWakeupTick = dwPriority;
			__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
			dwPriority = MAX_DWORD_VALUE - dwPriority;
			lpSleepingQueue->InsertIntoQueue((__COMMON_OBJECT*)lpSleepingQueue,
				(__COMMON_OBJECT*)lpKernelThread,
				dwPriority);
		}
	}

	goto __TERMINAL;

__TERMINAL:
	__ENTER_CRITICAL_SECTION(NULL,dwFlags);
	System.dwClockTickCounter ++;    //Update the system clock interrupt counter.
	__LEAVE_CRITICAL_SECTION(NULL,dwFlags);

	//KernelThreadManager.ScheduleFromInt((__COMMON_OBJECT*)&KernelThreadManager,
	//	lpEsp);

	return TRUE;
}


//
//The implementation of ConnectInterrupt routine of Interrupt Object.
//The routine do the following:
// 1. Insert the current object into interrupt object array(maintenanced by system object);
// 2. Set the object's data members correctly.
//

__COMMON_OBJECT* BOOL ConnectInterrupt(__COMMON_OBJECT*     lpThis,
							 __INTERRUPT_HANDLER  lpInterruptHandler,
							 LPVOID               lpHandlerParam,
							 UCHAR                ucVector,
							 UCHAR                ucReserved1,
							 UCHAR                ucReserved2,
							 UCHAR                ucInterruptMode,
							 BOOL                 bIfShared,
							 DWORD                dwCPUMask)
{
	__INTERRUPT_OBJECT*      lpInterrupt          = NULL;
	__INTERRUPT_OBJECT*      lpObjectRoot         = NULL;
	__SYSTEM*                lpSystem             = NULL;
	DWORD                    dwFlags              = 0L;

	if((NULL == lpThis) || (NULL == lpInterruptHandler))    //Parameters valid check.
		return NULL;

	if(ucVector >= MAX_INTERRUPT_VECTOR)                    //Impossible!!!
		return NULL;

	lpInterrupt = (__INTERRUPT_OBJECT*)
		ObjectManager.CreateObject(&ObjectManager,NULL,OBJECT_TYPE_INTERRUPT);
	if(NULL == lpInterrupt)    //Failed to create interrupt object.
		return FALSE;
	if(!lpInterrupt->Initialize((__COMMON_OBJECT*)lpInterrupt))  //Failed to initialize.
		return FALSE;

	lpInterrupt->lpPrevInterruptObject = NULL;
	lpInterrupt->lpNextInterruptObject = NULL;
	lpInterrupt->InterruptHandler      = lpInterruptHandler;
	lpInterrupt->lpHandlerParam        = lpHandlerParam;
	lpInterrupt->ucVector              = ucVector;

	__ENTER_CRITICAL_SECTION(NULL,dwFlags);
	lpObjectRoot = lpSystem->lpInterruptVector[ucVector];
	if(NULL == lpObjectRoot)    //If this is the first interrupt object of the vector.
	{
		System.lpInterruptVector[ucVector]  = lpInterrupt;
	}
	else
	{
		lpInterrupt->lpNextInterruptObject  = lpObjectRoot;
		lpObjectRoot->lpPrevInterruptObject = lpInterrupt;
		System.lpInterruptVector[ucVector]  = lpInterrupt;
	}
	//LEAVE_CRITICAL_SECTION();
	__LEAVE_CRITICAL_SECTION(NULL,dwFlags);

	return (__COMMON_OBJECT*)lpInterrupt;
}

//
//The implementation of DisconnectInterrupt.
//

static VOID DisconnectInterrupt(__COMMON_OBJECT* lpThis,
								__COMMON_OBJECT* lpInterrupt)
{
	__INTERRUPT_OBJECT*   lpIntObject    = NULL;
	__SYSTEM*             lpSystem       = NULL;
	UCHAR                 ucVector       = NULL;
	DWORD                 dwFlags        = 0L;

	if((NULL == lpThis) || (NULL == lpInterrupt)) //Parameters check.
		return;

	lpSystem = (__SYSTEM*)lpThis;
	lpIntObject = (__INTERRUPT_OBJECT*)lpInterrupt;
	ucVector    = lpIntObject->ucVector;

	//ENTER_CRITICAL_SECTION();
	__ENTER_CRITICAL_SECTION(NULL,dwFlags);
	if(NULL == lpIntObject->lpPrevInterruptObject)  //This is the first interrupt object.
	{
		lpSystem->lpInterruptVector[ucVector] = lpIntObject->lpNextInterruptObject;
		if(NULL != lpIntObject->lpNextInterruptObject) //Is not the last object.
		{
			lpIntObject->lpNextInterruptObject->lpPrevInterruptObject = NULL;
		}
	}
	else    //This is not the first object.
	{
		lpIntObject->lpPrevInterruptObject->lpNextInterruptObject = lpIntObject->lpNextInterruptObject;
		if(NULL != lpIntObject->lpNextInterruptObject)
		{
			lpIntObject->lpNextInterruptObject->lpPrevInterruptObject = lpIntObject->lpPrevInterruptObject;
		}
	}
	//LEAVE_CRITICAL_SECTION();
	__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
	return;
}

//
//The implementation of Initialize routine of interrupt object.
//

BOOL InterruptInitialize(__COMMON_OBJECT* lpThis)
{
	__INTERRUPT_OBJECT*    lpInterrupt = NULL;

	if(NULL == lpThis)
		return FALSE;

	lpInterrupt = (__INTERRUPT_OBJECT*)lpThis;
	lpInterrupt->lpPrevInterruptObject = NULL;
	lpInterrupt->lpNextInterruptObject = NULL;
	lpInterrupt->InterruptHandler      = NULL;
	lpInterrupt->lpHandlerParam        = NULL;
	lpInterrupt->ucVector              = 0L;
	return TRUE;
}

//
//The implementation of Uninitialize of interrupt object.
//This routine does nothing.
//

VOID InterruptUninitialize(__COMMON_OBJECT* lpThis)
{
	return;
}


//
//The implementation of timer object.
//

BOOL TimerInitialize(__COMMON_OBJECT* lpThis)    //Initializing routine of timer object.
{
	__TIMER_OBJECT*     lpTimer  = NULL;
	
	if(NULL == lpThis)
		return FALSE;

	lpTimer = (__TIMER_OBJECT*)lpThis;
	lpTimer->dwTimerID    = 0L;
	lpTimer->dwTimeSpan   = 0L;
	lpTimer->lpKernelThread      = NULL;
	lpTimer->lpHandlerParam      = NULL;
	lpTimer->DirectTimerHandler  = NULL;

	return TRUE;
}

//
//Uninitializing routine of timer object.
//

VOID TimerUninitialize(__COMMON_OBJECT* lpThis)
{
	return;
}

//-----------------------------------------------------------------------------------
//
//              The implementation of system object.
//
//------------------------------------------------------------------------------------

//
//Initializing routine of system object.
//The routine do the following:
// 1. Create a priority queue,to be used as lpTimerQueue,countains the timer object;
// 2. Create an interrupt object,as TIMER interrupt object;
// 3. Initialize system level variables,such as dwPhysicalMemorySize,etc.
//

static BOOL SystemInitialize(__COMMON_OBJECT* lpThis)
{
	__SYSTEM*            lpSystem         = NULL;
	__PRIORITY_QUEUE*    lpPriorityQueue  = NULL;
	__INTERRUPT_OBJECT*  lpIntObject      = NULL;
	BOOL                 bResult          = FALSE;
	DWORD                dwFlags          = 0L;

	if(NULL == lpThis)
		return FALSE;

	lpSystem = (__SYSTEM*)lpThis;
	lpPriorityQueue = (__PRIORITY_QUEUE*)ObjectManager.CreateObject(&ObjectManager,
		NULL,
		OBJECT_TYPE_PRIORITY_QUEUE);

	if(NULL == lpPriorityQueue)  //Failed to create priority queue.
		return FALSE;

	if(!lpPriorityQueue->Initialize((__COMMON_OBJECT*)lpPriorityQueue))  //Failed to initialize
		                                                                 //priority queue.
		goto __TERMINAL;
	lpSystem->lpTimerQueue = lpPriorityQueue;

	lpIntObject = (__INTERRUPT_OBJECT*)ObjectManager.CreateObject(
		&ObjectManager,
		NULL,
		OBJECT_TYPE_INTERRUPT);
	if(NULL == lpIntObject)
		goto __TERMINAL;

	bResult = lpIntObject->Initialize((__COMMON_OBJECT*)lpIntObject);
	if(!bResult)
		goto __TERMINAL;

	lpIntObject->ucVector = INTERRUPT_VECTOR_TIMER;
	lpIntObject->lpHandlerParam = NULL;
	lpIntObject->InterruptHandler = TimerInterruptHandler;

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
蜜臀国产一区二区三区在线播放| 亚洲不卡av一区二区三区| 欧美主播一区二区三区| 久久精品国产免费| 亚洲最大的成人av| 欧美日产国产精品| 国产精品一区二区久久不卡| 亚洲国产视频直播| 国产精品蜜臀av| 欧美成人性福生活免费看| 色哟哟国产精品| 国产69精品久久777的优势| 亚洲成人免费在线| 一区二区三区**美女毛片| 国产情人综合久久777777| 日韩视频免费直播| 欧美三级乱人伦电影| 99久久精品国产网站| 国产一区二区三区av电影 | 精品国产免费久久| 欧美日韩国产天堂| 日本高清免费不卡视频| 成人精品视频.| 国产成人综合在线观看| 免费欧美在线视频| 三级久久三级久久久| 亚洲第一综合色| 亚洲一区欧美一区| 亚洲美腿欧美偷拍| 色综合久久综合网| 91精品国产福利| 日本丶国产丶欧美色综合| 国产99精品在线观看| 精品无人区卡一卡二卡三乱码免费卡| 亚洲成人av在线电影| 一区二区三区日韩欧美精品| 亚洲视频免费在线观看| 综合av第一页| 亚洲精品福利视频网站| 亚洲免费视频中文字幕| 亚洲欧美日韩小说| 亚洲免费大片在线观看| 中文字幕一区二区三区四区 | 91亚洲国产成人精品一区二区三| 国产成人综合在线| 不卡的av在线| 99国内精品久久| 色欧美乱欧美15图片| 欧美亚洲丝袜传媒另类| 欧美在线free| 9191精品国产综合久久久久久| 国产露脸91国语对白| 欧美国产综合一区二区| 国产精品视频看| 中文字幕日本乱码精品影院| 亚洲免费高清视频在线| 亚洲va国产va欧美va观看| 日本伊人精品一区二区三区观看方式| 日韩成人免费电影| 韩国精品主播一区二区在线观看 | 韩国成人福利片在线播放| 精品一区二区在线视频| 成人看片黄a免费看在线| 97久久精品人人爽人人爽蜜臀| 日本高清不卡视频| 日韩一区二区三区四区五区六区| 精品国产乱码久久久久久牛牛 | 4438x成人网最大色成网站| 欧美一区在线视频| 成人av高清在线| 一本大道久久a久久精二百 | 欧美日韩国产美| 久久这里只有精品首页| 亚洲精品自拍动漫在线| 麻豆精品久久精品色综合| 成人免费黄色在线| 欧美男男青年gay1069videost | xvideos.蜜桃一区二区| 亚洲色图在线视频| 日本大胆欧美人术艺术动态| 国产高清视频一区| 欧洲一区二区三区在线| 欧美变态口味重另类| 自拍偷拍欧美精品| 男女男精品视频| 91丨九色丨蝌蚪丨老版| 日韩亚洲欧美高清| 最新高清无码专区| 另类小说综合欧美亚洲| 在线视频你懂得一区| 欧美大胆一级视频| 伊人色综合久久天天人手人婷| 麻豆成人91精品二区三区| 91在线国内视频| 久久天堂av综合合色蜜桃网| 夜夜嗨av一区二区三区| 丰满亚洲少妇av| 日韩西西人体444www| 亚洲精品ww久久久久久p站| 亚洲国产wwwccc36天堂| 91精品在线麻豆| 国产精品拍天天在线| 美日韩一区二区三区| 91麻豆免费观看| 久久久99精品免费观看| 首页欧美精品中文字幕| 99视频国产精品| 久久久www成人免费无遮挡大片| 午夜精品一区二区三区电影天堂| 成人午夜电影久久影院| 精品久久久久av影院| 亚洲成人福利片| 欧洲人成人精品| 国产精品色眯眯| 国产麻豆成人精品| 欧美一区二区视频在线观看| 亚洲精品综合在线| av日韩在线网站| 久久精品这里都是精品| 理论电影国产精品| 欧美日韩一区二区三区在线| 最新日韩在线视频| 成人国产在线观看| 精品福利av导航| 麻豆一区二区三| 欧美精品v国产精品v日韩精品 | 欧美一区二区三区小说| 一区二区三区不卡视频| 色综合天天综合色综合av| 国产精品毛片久久久久久| 国产成人激情av| 久久久精品免费网站| 国产在线精品一区二区| 欧美精品一区二区久久婷婷| 日本麻豆一区二区三区视频| 91精品国产福利| 捆绑紧缚一区二区三区视频| 欧美一卡二卡在线| 日本不卡的三区四区五区| 在线不卡一区二区| 日韩 欧美一区二区三区| 欧美日韩久久不卡| 午夜a成v人精品| 这里是久久伊人| 美女视频免费一区| 精品国产精品一区二区夜夜嗨 | 欧美日韩久久久久久| 首页国产丝袜综合| 精品欧美乱码久久久久久| 韩国欧美国产1区| 国产视频不卡一区| 99天天综合性| 一区二区三区四区不卡视频| 欧美日韩一区二区三区不卡| 无码av免费一区二区三区试看| 91超碰这里只有精品国产| 麻豆精品一区二区综合av| 久久午夜电影网| 99久久综合精品| 亚洲精品国久久99热| 欧美日韩精品免费| 美女视频一区二区| 国产欧美一区二区精品性| 91网站在线观看视频| 亚洲va欧美va人人爽午夜| 欧美一个色资源| 福利视频网站一区二区三区| 亚洲精品免费一二三区| 欧美一区二区精品在线| 国产成人精品1024| 亚洲综合免费观看高清完整版在线 | 久久机这里只有精品| 国产三级一区二区三区| 日本精品视频一区二区| 久久国产人妖系列| 国产精品乱人伦中文| 欧美日本乱大交xxxxx| 国产精品一品二品| 成人黄色综合网站| 亚洲高清免费观看高清完整版在线观看| 日韩一级视频免费观看在线| av影院午夜一区| 日韩成人一级片| 国产精品久线在线观看| 欧美一区二区三区四区在线观看| 粗大黑人巨茎大战欧美成人| 午夜久久久久久久久| 欧美激情在线看| 7777精品伊人久久久大香线蕉超级流畅 | 极品美女销魂一区二区三区免费| 专区另类欧美日韩| 欧美一区二区在线播放| 91麻豆免费观看| 国产精品一级黄| 日韩高清在线不卡| 国产精品毛片无遮挡高清| 日韩一区二区三区免费观看| 91美女片黄在线观看| 精品亚洲porn| 日本人妖一区二区|