Ejemplo n.º 1
0
//
//Entry point of the text mode shell.
//
DWORD ShellEntryPoint(LPVOID pData)
{
	__KERNEL_THREAD_MESSAGE KernelThreadMessage;

	//Print out version and author information.
	//GotoHome();
	//ChangeLine();
	//PrintStr(VERSION_INFO);
	GotoHome();
	ChangeLine();

	PrintPrompt();
	while(TRUE)
	{
		if(GetMessage(&KernelThreadMessage))
		{
			if(KERNEL_MESSAGE_TERMINAL == KernelThreadMessage.wCommand)
			{
				break;
			}
			DispatchMessage(&KernelThreadMessage,EventHandler);
		}
	}

	//When reach here,it means the shell thread will terminate.We will reboot
	//the system in current version's implementation,since there is no interact
	//mechanism between user and computer in case of no shell.
	//NOTE:System clean up operations should be put here if necessary.
#ifdef __I386__
	BIOSReboot();
#endif
	return 0;
}
Ejemplo n.º 2
0
//
//Print a string at a new line.
//
VOID PrintLine(LPSTR pszStr)
{
	//CD_PrintString(pszStr,TRUE);
	GotoHome();
	ChangeLine();
	PrintStr(pszStr);
}
Ejemplo n.º 3
0
//Default handler if no proper handler is located.
VOID  DefaultHandler(LPSTR pstr)
{
	LPSTR strPrompt = "You entered incorrect command name.";
	GotoHome();
	ChangeLine();
	PrintStr(strPrompt);
	return;
}
Ejemplo n.º 4
0
static VOID PrintPound()
{
	WORD  wr = 0x0700;
	
	wr += '#';
	GotoHome();
	ChangeLine();
	PrintCh(wr);
}
Ejemplo n.º 5
0
//Internal routine to print version info.
static VOID __VersionInfo()
{
	LPSTR       lpszVersion   = "hedit - Hello China Editor,version 0.1";

	//Print out version info.
	GotoHome();
	ChangeLine();
	PrintLine(lpszVersion);
}
Ejemplo n.º 6
0
//Initialization routine of Console object.
static BOOL ConInitialize(__CONSOLE* pConsole)
{
	__COMMON_OBJECT* hCom1  = NULL;
	if(NULL == pConsole)
	{
		return FALSE;
	}

	//Try to open COM1 interface.
	hCom1 = IOManager.CreateFile(
		(__COMMON_OBJECT*)&IOManager,
		CON_DEF_COMNAME,
		0,
		0,
		NULL);

	//debug
	PrintLine("hCom1="); PrintLine(hCom1);

	if(NULL == hCom1)
	{
		return FALSE;
	}

	pConsole->hComInt      = hCom1;
	pConsole->bInitialized = TRUE;
	pConsole->nRowNum      = CON_MAX_ROWNUM;
	pConsole->nColNum      = CON_MAX_COLNUM;

	//Create console read thread to process COM interface input message.
	pConsole->hConThread = KernelThreadManager.CreateKernelThread(
		(__COMMON_OBJECT*)&KernelThreadManager,
		0,
		KERNEL_THREAD_STATUS_READY,
		PRIORITY_LEVEL_HIGH,
		ConReadThread,
		NULL,
		NULL,
		CON_THREAD_NAME);

	PrintStr("pConsole=");
	PrintStr(pConsole);
	GotoHome();

	if(NULL == pConsole->hConThread)  //Failed to create thread.
	{
		IOManager.CloseFile((__COMMON_OBJECT*)&IOManager,pConsole->hComInt);
		pConsole->hComInt      = NULL;
		pConsole->bInitialized = FALSE;
		return FALSE;
	}
	return TRUE;
}
Ejemplo n.º 7
0
//Main entry of HEDIT application.
DWORD heditEntry(LPVOID lpParam)
{
#ifdef __CFG_SYS_DDF
	LPSTR       lpszParam     = (LPSTR)lpParam;
	HANDLE      hFile         = NULL;
	LPSTR       lpszNoTarget  = "  Please specify the target file to write.";
	LPSTR       lpszFileName  = NULL;

	if(NULL == lpszParam)
	{
		PrintLine(lpszNoTarget);
		goto __TERMINAL;
	}
	if(0 == lpszParam[0])
	{
		PrintLine(lpszNoTarget);
		goto __TERMINAL;
	}
	//Skip the space before file name in parameter string.
	lpszFileName = lpszParam;
	while(' ' == *lpszFileName)
	{
		lpszFileName ++;
	}

	hFile = CreateEditFile(lpszFileName);
	if(NULL == hFile)  //Can not create the target file.
	{
		PrintLine("  Can not create the target file.");
		PrintLine(lpszParam);  //For debugging.
		goto __TERMINAL;
	}
	//Process user input and save to file.
	GotoHome();
	ChangeLine();
	__UserInput(hFile);
	//When user terminates this application,print out version information.
	__VersionInfo();

__TERMINAL:
	if(hFile)  //Close it.
	{
		IOManager.CloseFile((__COMMON_OBJECT*)&IOManager,
			hFile);
	}
	return 0;
#else
	return 0;
#endif
}
Ejemplo n.º 8
0
//Main entry of HEDIT application.
DWORD heditEntry(LPVOID lpParam)
{
#ifdef __CFG_SYS_DDF
	__CMD_PARA_OBJ* pCmdParaObj = (__CMD_PARA_OBJ*)lpParam;
	//LPSTR       lpszParam     = (LPSTR)lpParam;
	HANDLE      hFile         = NULL;
	LPSTR       lpszNoTarget  = "  Please specify the target file to write.";
	LPSTR       lpszFileName  = NULL;

	if(NULL == pCmdParaObj || pCmdParaObj->byParameterNum < 2)
	{
		PrintLine(lpszNoTarget);
		goto __TERMINAL;
	}

	hFile = CreateEditFile(pCmdParaObj->Parameter[1]);
	if(NULL == hFile)  //Can not create the target file.
	{
		PrintLine("  Can not create the target file.");
		PrintLine(pCmdParaObj->Parameter[1]);  //For debugging.
		goto __TERMINAL;
	}
	//Process user input and save to file.
	GotoHome();
	ChangeLine();
	__UserInput(hFile);
	//When user terminates this application,print out version information.
	__VersionInfo();

__TERMINAL:
	if(hFile)  //Close it.
	{
		IOManager.CloseFile((__COMMON_OBJECT*)&IOManager,
			hFile);
	}
	return 0;
#else
	return 0;
#endif
}
Ejemplo n.º 9
0
//
//The main entry of OS.When the OS kernel is loaded into memory and all hardware
//context is initialized OK,Hello China OS's kernel will run from here.
//This is a never finish(infinite) routine and will never end unless powers off 
//the system or reboot the system.
//It's main functions are initializing all system level objects and modules,loading kernel
//mode hardware drivers,loading external function modules(such as GUI and network),then
//creating several kernel thread(s) and entering a dead loop.
//But the dead loop codes only run a short time since the kernel thread(s) will be 
//scheduled once system clock occurs and the dead loop will end.
//
void __OS_Entry()
{
	__KERNEL_THREAD_OBJECT*       lpIdleThread     = NULL;
	__KERNEL_THREAD_OBJECT*       lpShellThread    = NULL;
#ifdef __CFG_USE_EOS
	__KERNEL_THREAD_OBJECT*       lpUserThread     = NULL;
#endif
	DWORD                         dwIndex          = 0;
	CHAR                          strInfo[64];
	char*                         pszErrorMsg      = "INIT: OK";

	//Print out welcome message.
	//Please note the output should put here that before the System.BeginInitialization routine,
	//since it may cause the interrupt enable,which will lead the failure of system initialization.
	/*ClearScreen();
	PrintStr(pszStartMsg1);
	PrintStr(pszStartMsg2);
	GotoHome();
	ChangeLine();

	PrintStr(pszHelpInfo); //Print out help information.
	GotoHome();
	ChangeLine();*/

	//Prepare the OS initialization environment.It's worth noting that even the System
	//object self is not initialized yet.
	if(!System.BeginInitialize((__COMMON_OBJECT*)&System))
	{
		pszErrorMsg = "INIT ERROR: System.BeginInitialization routine failed.";
		goto __TERMINAL;
	}

	//Initialize memory management object.This object must be initialized before any other
	//system level objects since it's function maybe required by them.
	if(!AnySizeBuffer.Initialize(&AnySizeBuffer))
	{
		pszErrorMsg = "INIT ERROR: Failed to initialize AnySizeBuffer object.";
		goto __TERMINAL;
	}

#ifdef __I386__
	// load display device
	dwIndex = 0;
	while(DisplayEntryArray[dwIndex])
	{
		if(!DisplayManager.LoadDisplay(DisplayEntryArray[dwIndex])) //Failed to load.
		{
			//sprintf(strInfo,"Failed to load the %dth driver.",dwIndex); //Show an error.
			//PrintLine(strInfo);
		}
		dwIndex ++;  //Continue to load.
	}
	CD_InitDisplay(0);
#endif

	ClearScreen();
	PrintStr(pszStartMsg1);
	PrintStr(pszStartMsg2);
	GotoHome();
	ChangeLine();

	PrintStr(pszHelpInfo); //Print out help information.
	GotoHome();
	ChangeLine();

#ifdef __CFG_SYS_VMM  //Enable VMM.
	*(__PDE*)PD_START = NULL_PDE;    //Set the first page directory entry to NULL,to indicate
	//this location is not initialized yet.
#endif


	//********************************************************************************
	//
	//The following code initializes system level global objects.
	//
	//********************************************************************************

#ifdef __CFG_SYS_VMM    //Should enable virtual memory model.
	lpVirtualMemoryMgr = (__VIRTUAL_MEMORY_MANAGER*)ObjectManager.CreateObject(&ObjectManager,
		NULL,
		OBJECT_TYPE_VIRTUAL_MEMORY_MANAGER);    //Create virtual memory manager object.
	if(NULL == lpVirtualMemoryMgr)    //Failed to create this object.
	{
		pszErrorMsg = "INIT ERROR: Can not create VirtualMemoryManager object.";
		goto __TERMINAL;
	}

	if(!lpVirtualMemoryMgr->Initialize((__COMMON_OBJECT*)lpVirtualMemoryMgr))
	{
		pszErrorMsg = "INIT ERROR: Can not initialize VirtualMemoryManager object.";
		goto __TERMINAL;
	}
#endif

	//Initialize Kernel Thread Manager object.
	if(!KernelThreadManager.Initialize((__COMMON_OBJECT*)&KernelThreadManager))
	{
		pszErrorMsg = "INIT ERROR: Can not initialize KernelThreadManager object.";
		goto __TERMINAL;
	}

	//Initialize System object.
	if(!System.Initialize((__COMMON_OBJECT*)&System))
	{
		pszErrorMsg = "INIT ERROR: Can not initialize System object.";
		goto __TERMINAL;
	}

	//Set the general interrupt handler,after this action,interrupt and
	//exceptions in system can be handled by System object.
	//This routine must be called earlier than any modules who will use
	//system call.
#ifdef __I386__
	SetGeneralIntHandler(GeneralIntHandler);
#endif

#ifdef __CFG_SYS_VMM
	//Initialize PageFrmaeManager object.
	if(!PageFrameManager.Initialize((__COMMON_OBJECT*)&PageFrameManager,
		(LPVOID)0x02000000,
		(LPVOID)0x09FFFFFF))
	{
		pszErrorMsg = "INIT ERROR: Can not initialize PageFrameManager object.";
		goto __TERMINAL;
	}
#endif

	//Device Driver Framework related global functions.
#ifdef __CFG_SYS_DDF
	//Initialize IOManager object.
	if(!IOManager.Initialize((__COMMON_OBJECT*)&IOManager))
	{
		pszErrorMsg = "INIT ERROR: Can not initialize IOManager object.";
		goto __TERMINAL;
	}

	//Initialize DeviceManager object.
	if(!DeviceManager.Initialize(&DeviceManager))
	{
		pszErrorMsg = "INIT ERROR: Can not initialize DeviceManager object.";
		goto __TERMINAL;
	}
#endif

	//Initialize CPU statistics object.
#ifdef __CFG_SYS_CPUSTAT
	if(!StatCpuObject.Initialize(&StatCpuObject))
	{
		pszErrorMsg = "INIT ERROR: Can not initialize StatCpuObject.";
		goto __TERMINAL;
	}
#endif

	//Enable the virtual memory management mechanism if __CFG_SYS_VMM flag is defined.
#ifdef __CFG_SYS_VMM
	EnableVMM();
#endif

	//********************************************************************************
	//
	//The following code loads all inline device drivers,and external drivers implemented as
	//external module.
	//
	//********************************************************************************
#ifdef __CFG_SYS_DDF
	dwIndex = 0;
	while(DriverEntryArray[dwIndex])
	{
		if(!IOManager.LoadDriver(DriverEntryArray[dwIndex])) //Failed to load.
		{
			_hx_sprintf(strInfo,"Failed to load the %dth driver.",dwIndex); //Show an error.
			PrintLine(strInfo);
		}
		dwIndex ++;  //Continue to load.
	}
#endif

	//Initialize Console object if necessary.
#ifdef __CFG_SYS_CONSOLE
	if(!Console.Initialize(&Console))
	{
		pszErrorMsg = "INIT ERROR: Can not initialize Console object.";
		goto __TERMINAL;
	}
#endif
	//BISStartup();

	//********************************************************************************
	//
	//The following code creates all system level kernel threads.
	//
	//********************************************************************************

	//The first one is IDLE thread,which will be scheduled when no thread need to schedule,
	//so it's priority is the lowest one in system,which is PRIORITY_LEVEL_LOWEST.
	//Also need to mention that this thread is mandatory and without any switch to turn off
	//it.
	lpIdleThread = KernelThreadManager.CreateKernelThread(
		(__COMMON_OBJECT*)&KernelThreadManager,
		0,
		KERNEL_THREAD_STATUS_READY,
		PRIORITY_LEVEL_LOWEST,
		SystemIdle,
		NULL,
		NULL,
		"IDLE");
	if(NULL == lpIdleThread)
	{
		pszErrorMsg = "INIT ERROR: Can not create SystemIdle kernel thread.";
		goto __TERMINAL;
	}

	//Create statistics kernel thread.
#ifdef __CFG_SYS_CPUSTAT
	lpStatKernelThread = KernelThreadManager.CreateKernelThread(
		(__COMMON_OBJECT*)&KernelThreadManager,
		0,
		KERNEL_THREAD_STATUS_READY,
		PRIORITY_LEVEL_HIGH,  //With high priority.
		StatThreadRoutine,
		NULL,
		NULL,
		"CPU STAT");
	if(NULL == lpStatKernelThread)
	{
		pszErrorMsg = "INIT ERROR: Can not create CPU_Stat kernel thread.";
		goto __TERMINAL;
	}
#endif

	//Create shell thread.The shell thread's implementation code resides in shell.cpp
	//file in shell directory.
#ifdef __CFG_SYS_SHELL  //Shell can be eleminated by turn off this switch.
	if(NULL == ModuleMgr.ShellEntry)  //Use default shell.
	{
		lpShellThread = KernelThreadManager.CreateKernelThread(   //Create shell thread.
			(__COMMON_OBJECT*)&KernelThreadManager,
			0,
			KERNEL_THREAD_STATUS_READY,
			PRIORITY_LEVEL_HIGH,
			ShellEntryPoint,
			NULL,
			NULL,
			"SHELL");
		if(NULL == lpShellThread)
		{
			pszErrorMsg = "INIT ERROR: Can not create Shell kernel thread.";
			goto __TERMINAL;
		}
	}
	else    //Use other kernel module specified shell.
	{
		lpShellThread = KernelThreadManager.CreateKernelThread(   //Create shell thread.
			(__COMMON_OBJECT*)&KernelThreadManager,
			0,
			KERNEL_THREAD_STATUS_READY,
			PRIORITY_LEVEL_HIGH,
			ModuleMgr.ShellEntry,
			NULL,
			NULL,
			"SHELL");
		if(NULL == lpShellThread)
		{
			pszErrorMsg = "INIT ERROR: Can not create Shell kernel thread.";
			goto __TERMINAL;
		}
	}
	g_lpShellThread = lpShellThread;     //Initialize the shell thread global variable.

	//Print out the default system prompt,which can be changed by 'sysname' command.
	//strcpy(&HostName[0],"[system-view]");
#endif

	//Initialize DeviceInputManager object.
	if(!DeviceInputManager.Initialize((__COMMON_OBJECT*)&DeviceInputManager,
		NULL,
		(__COMMON_OBJECT*)lpShellThread))
	{
		pszErrorMsg = "INIT ERROR: Can not initialize DeviceInputManager object.";
		goto __TERMINAL;
	}

	//********************************************************************************
	//
	//The following code creates user's main kernel thread if used as EOS.
	//
	//********************************************************************************

	//Create user kernel thread.
#ifdef __CFG_USE_EOS
	lpUserThread = KernelThreadManager.CreateKernelThread(   //Create shell thread.
		(__COMMON_OBJECT*)&KernelThreadManager,
		0,
		KERNEL_THREAD_STATUS_READY,
		__HCNMAIN_PRIORITY,
		_HCNMain,
		NULL,
		NULL,
		__HCNMAIN_NAME);
	if(NULL == lpUserThread)
	{
		pszErrorMsg = "INIT ERROR: Can not create User_Main kernel thread.";
		goto __TERMINAL;
	}
#endif

	//If log debugging functions is enabled.
#ifdef __CFG_SYS_LOGCAT
	DebugManager.Initialize(&DebugManager);
	lpLogcatDaemonThread = KernelThreadManager.CreateKernelThread(   //Create logcat daemon thread.
		(__COMMON_OBJECT*)&KernelThreadManager,
		0,
		KERNEL_THREAD_STATUS_READY,
		PRIORITY_LEVEL_NORMAL,
		LogcatDaemon,
		NULL,
		NULL,
		"Logcat Daemon");
	if(NULL == lpLogcatDaemonThread)
	{
		pszErrorMsg = "INIT ERROR: Can not create Logcat_Daemon object.";
		goto __TERMINAL;
	}

#endif  //__CFG_SYS_LOGCAT.

#ifdef __CFG_NET_IPv4  //IPv4 network protocol is enabled.
	if(!IPv4_Entry(NULL))
	{
		pszErrorMsg = "INIT ERROR: Can not initialize IPv4 protocol function.";
		goto __TERMINAL;
	}
	if(!InitializeEthernetIf())
	{
		pszErrorMsg = "INIT ERROR: Can not initialize Ethernet interface.";
		goto __TERMINAL;
	}
#endif

	System.EndInitialize((__COMMON_OBJECT*)&System);
	//Enter a dead loop to wait for the scheduling of kernel threads.
	DeadLoop();

	//The following code will never be executed if corrected.
__TERMINAL:
	GotoHome();
	ChangeLine();
	PrintLine(pszErrorMsg);  //Show error msg.
	DeadLoop();
}
Ejemplo n.º 10
0
Archivo: string.c Proyecto: csl/PXACore
//
//Print a string at a new line.
//
VOID PrintLine(LPSTR pszStr)
{
	GotoHome();
	ChangeLine();
	PrintStr(pszStr);
}
Ejemplo n.º 11
0
//
//The main entry of OS.When the OS kernel is loaded into memory and all hardware
//context is initialized OK,Hello China OS's kernel will run from here.
//This is a never finish(infinite) routine and will never end unless powers off 
//the system or reboot the system.
//It's main functions are initializing all system level objects and modules,loading kernel
//mode hardware drivers,loading external function modules(such as GUI and network),then
//creating several kernel thread(s) and entering a dead loop.
//But the dead loop codes only run a short time since the kernel thread(s) will be 
//scheduled once system clock occurs and the dead loop will end.
//
void __OS_Entry()
{
	__KERNEL_THREAD_OBJECT*       lpIdleThread     = NULL;
	__KERNEL_THREAD_OBJECT*       lpShellThread    = NULL;
#ifdef __CFG_USE_EOS
	__KERNEL_THREAD_OBJECT*       lpUserThread     = NULL;
#endif
	DWORD                         dwIndex          = 0;
	CHAR                          strInfo[64];

	//Prepare the OS initialization environment.It's worth noting that even the System
	//object self is not initialized yet.
	if(!System.BeginInitialize((__COMMON_OBJECT*)&System))
	{
		goto __TERMINAL;
	}

	//Initialize memory management object.This object must be initialized before any other
	//system level objects since it's function maybe required by them.
	if(!AnySizeBuffer.Initialize(&AnySizeBuffer))
	{
		goto __TERMINAL;
	}

	//Print out welcome message.
	ClearScreen();
	PrintStr(pszStartMsg1);
	PrintStr(pszStartMsg2);
	GotoHome();
	ChangeLine();

	PrintStr(pszHelpInfo); //Print out help information.
	GotoHome();
	ChangeLine();

#ifdef __CFG_SYS_VMM  //Enable VMM.
	*(__PDE*)PD_START = NULL_PDE;    //Set the first page directory entry to NULL,to indicate
	                                 //this location is not initialized yet.
#endif


	//********************************************************************************
	//
	//The following code initializes system level global objects.
	//
	//********************************************************************************

#ifdef __CFG_SYS_VMM    //Should enable virtual memory model.
	lpVirtualMemoryMgr = (__VIRTUAL_MEMORY_MANAGER*)ObjectManager.CreateObject(&ObjectManager,
		NULL,
		OBJECT_TYPE_VIRTUAL_MEMORY_MANAGER);    //Create virtual memory manager object.
	if(NULL == lpVirtualMemoryMgr)    //Failed to create this object.
	{
		goto __TERMINAL;
	}

	if(!lpVirtualMemoryMgr->Initialize((__COMMON_OBJECT*)lpVirtualMemoryMgr))
	{
		goto __TERMINAL;
	}
#endif
	
	//Initialize Kernel Thread Manager object.
	if(!KernelThreadManager.Initialize((__COMMON_OBJECT*)&KernelThreadManager))
	{
		goto __TERMINAL;
	}

	//Initialize System object.
	if(!System.Initialize((__COMMON_OBJECT*)&System))
	{
		goto __TERMINAL;
	}

	//Set the general interrupt handler,after this action,interrupt and
	//exceptions in system can be handled by System object.
	//This routine must be called earlier than any modules who will use
	//system call.
#ifdef __I386__
	SetGeneralIntHandler(GeneralIntHandler);
#endif

#ifdef __CFG_SYS_VMM
	//Initialize PageFrmaeManager object.
	if(!PageFrameManager.Initialize((__COMMON_OBJECT*)&PageFrameManager,
		(LPVOID)0x02000000,
		(LPVOID)0x09FFFFFF))
	{
		goto __TERMINAL;
	}
#endif

	//Device Driver Framework related global functions.
#ifdef __CFG_SYS_DDF
	//Initialize IOManager object.
	if(!IOManager.Initialize((__COMMON_OBJECT*)&IOManager))
	{
		goto __TERMINAL;
	}

	//Initialize DeviceManager object.
	if(!DeviceManager.Initialize(&DeviceManager))
	{
	    goto __TERMINAL;
	}
#endif

	//Initialize CPU statistics object.
#ifdef __CFG_SYS_CPUSTAT
	if(!StatCpuObject.Initialize(&StatCpuObject))
	{
		goto __TERMINAL;
	}
#endif

	//Enable the virtual memory management mechanism if __CFG_SYS_VMM flag is defined.
#ifdef __CFG_SYS_VMM
	EnableVMM();
#endif

	//********************************************************************************
	//
	//The following code loads all inline device drivers,and external drivers implemented as
	//external module.
	//
	//********************************************************************************
#ifdef __CFG_SYS_DDF
	dwIndex = 0;
	while(DriverEntryArray[dwIndex])
	{
		if(!IOManager.LoadDriver(DriverEntryArray[dwIndex])) //Failed to load.
		{
			sprintf(strInfo,"Failed to load the %dth driver.",dwIndex); //Show an error.
			PrintLine(strInfo);
		}
		dwIndex ++;  //Continue to load.
	}

	//Initialize module manager object.
	//if(!ModuleMgr.Initialize(&ModuleMgr))
	//{
	//	PrintLine("  Can not initialize module manager object.");
	//	goto __TERMINAL;
	//}
#endif

	//Initialize Console object if necessary.
#ifdef __CFG_SYS_CONSOLE
	if(!Console.Initialize(&Console))
	{
		PrintLine("Can not initialize Console object.");
	}
	else
	{
		//PrintLine("Initialize Console object successfully.");
	}
#endif

	//Load external modules.
	//ModuleMgr.LoadExternalMod("MODCFG.INI");     //MODCFG.INI is the module's configure file.
	//PrintLine("Load external module is disabled for debugging.");

	//********************************************************************************
	//
	//The following code creates all system level kernel threads.
	//
	//********************************************************************************

	//The first one is IDLE thread,which will be scheduled when no thread need to schedule,
	//so it's priority is the lowest one in system,which is PRIORITY_LEVEL_LOWEST.
	//Also need to mention that this thread is mandatory and without any switch to turn off
	//it.
	lpIdleThread = KernelThreadManager.CreateKernelThread(
		(__COMMON_OBJECT*)&KernelThreadManager,
		0,
		KERNEL_THREAD_STATUS_READY,
		PRIORITY_LEVEL_LOWEST,
		SystemIdle,
		NULL,
		NULL,
		"IDLE");
	if(NULL == lpIdleThread)
	{
		//PrintLine("Can not create idle kernel thread,please restart the system.");
		__ERROR_HANDLER(ERROR_LEVEL_FATAL,0,NULL);
		goto __TERMINAL;
	}

	//Create statistics kernel thread.
#ifdef __CFG_SYS_CPUSTAT
	lpStatKernelThread = KernelThreadManager.CreateKernelThread(
		(__COMMON_OBJECT*)&KernelThreadManager,
		0,
		KERNEL_THREAD_STATUS_READY,
		PRIORITY_LEVEL_HIGH,  //With high priority.
		StatThreadRoutine,
		NULL,
		NULL,
		"CPU STAT");
	if(NULL == lpStatKernelThread)
	{
		//PrintLine("Can not create idle kernel thread,please restart the system.");
		__ERROR_HANDLER(ERROR_LEVEL_FATAL,0,NULL);
		goto __TERMINAL;
	}
#endif

	//Create shell thread.The shell thread's implementation code resides in shell.cpp
	//file in shell directory.
#ifdef __CFG_SYS_SHELL  //Shell can be eleminated by turn off this switch.
	if(NULL == ModuleMgr.ShellEntry)  //Use default shell.
	{
		lpShellThread = KernelThreadManager.CreateKernelThread(   //Create shell thread.
			(__COMMON_OBJECT*)&KernelThreadManager,
			0,
			KERNEL_THREAD_STATUS_READY,
			PRIORITY_LEVEL_NORMAL,
			ShellEntryPoint,
			NULL,
			NULL,
			"SHELL");
		if(NULL == lpShellThread)
		{
			__ERROR_HANDLER(ERROR_LEVEL_FATAL,0,NULL);
			goto __TERMINAL;
		}
	}
	else    //Use other kernel module specified shell.
	{
		lpShellThread = KernelThreadManager.CreateKernelThread(   //Create shell thread.
			(__COMMON_OBJECT*)&KernelThreadManager,
			0,
			KERNEL_THREAD_STATUS_READY,
			PRIORITY_LEVEL_NORMAL,
			ModuleMgr.ShellEntry,
			NULL,
			NULL,
			"SHELL");
		if(NULL == lpShellThread)
		{
			__ERROR_HANDLER(ERROR_LEVEL_FATAL,0,NULL);
			goto __TERMINAL;
		}
	}
	g_lpShellThread = lpShellThread;     //Initialize the shell thread global variable.
	
	//Print out the default system prompt,which can be changed by 'sysname' command.
	strcpy(&HostName[0],"[system-view]");
#endif

	//Initialize DeviceInputManager object.
	if(!DeviceInputManager.Initialize((__COMMON_OBJECT*)&DeviceInputManager,
		                              NULL,
		                              (__COMMON_OBJECT*)lpShellThread))
	{
		__ERROR_HANDLER(ERROR_LEVEL_FATAL,0,NULL);
		goto __TERMINAL;
	}

	//********************************************************************************
	//
	//The following code creates user's main kernel thread if used as EOS.
	//
	//********************************************************************************

	//Create user kernel thread.
#ifdef __CFG_USE_EOS
		lpUserThread = KernelThreadManager.CreateKernelThread(   //Create shell thread.
			(__COMMON_OBJECT*)&KernelThreadManager,
			0,
			KERNEL_THREAD_STATUS_READY,
			__HCNMAIN_PRIORITY,
			_HCNMain,
			NULL,
			NULL,
			__HCNMAIN_NAME);
		if(NULL == lpUserThread)
		{
			__ERROR_HANDLER(ERROR_LEVEL_FATAL,0,NULL);
			goto __TERMINAL;
		}
#endif

	//Finish OS initialization phase by calling EndInitialize routine of System object,coresponding the
	//BeginInitialize routine call before initialization.
	System.EndInitialize((__COMMON_OBJECT*)&System);

	//Enter a dead loop to wait for the scheduling of kernel threads.
	DeadLoop();

	//The following code will never be executed if corrected.
__TERMINAL:
	GotoHome();
	ChangeLine();
	__ERROR_HANDLER(ERROR_LEVEL_FATAL,0,"Initializing process failed!");
	DeadLoop();
}
Ejemplo n.º 12
0
//Process user input.
//This is a private function can only be called by heditEntry.
static VOID __UserInput(HANDLE hFile)
{
#ifdef __CFG_SYS_DDF
	BYTE*                       pDataBuffer      = NULL;
	BYTE*                       pCurrPos         = NULL;
	DWORD                       dwDefaultSize    = 8192;      //Default file size is 8K.
	BOOL                        bCtrlDown        = FALSE;
	BYTE                        bt;
	WORD                        wr                            = 0x0700;
	__KERNEL_THREAD_MESSAGE     Msg;
	DWORD                       dwWrittenSize    = 0;

	pDataBuffer = (BYTE*)KMemAlloc(dwDefaultSize,KMEM_SIZE_TYPE_ANY);
	if(NULL == pDataBuffer)
	{
		PrintLine("  Can not allocate memory.");
		goto __TERMINAL;
	}
	pCurrPos = pDataBuffer;

	while(TRUE)
	{
		if(GetMessage(&Msg))
		{
			if(MSG_KEY_DOWN == Msg.wCommand)    //This is a key down message.
			{
				bt = (BYTE)Msg.dwParam;
				switch(bt)
				{
				case VK_RETURN:                  //This is a return key.
					if((DWORD)(pCurrPos - pDataBuffer) < dwDefaultSize - 2)
					{
						*pCurrPos ++ = '\r';     //Append a return key.
						*pCurrPos ++ = '\n';
						GotoHome();
						ChangeLine();            //Change to next line.
					}
					break;
				case VK_BACKSPACE:
					if(*pCurrPos == '\n')  //Enter encountered.
					{
						pCurrPos -= 2;     //Skip the \r\n.
					}
					else
					{
						pCurrPos -= 1;
					}
					GotoPrev();
					break;
				default:
					if(('c' == bt) || ('C' == bt) || ('z' == bt) || ('Z' == bt))
					{
						if(bCtrlDown)  //CtrlC or CtrlZ encountered.
						{
							goto __TERMINAL;
						}
					}
					if((DWORD)(pCurrPos - pDataBuffer) < dwDefaultSize)
					{
						*pCurrPos ++ = bt; //Save this character.
						wr += bt;
						PrintCh(wr);
						wr  = 0x0700;
					}
					break;
				}
			}
			else
			{
				if(VIRTUAL_KEY_DOWN == Msg.wCommand)
				{
					bt = (BYTE)Msg.dwParam;
					if(VK_CONTROL == bt)
					{
						bCtrlDown = TRUE;
					}
				}
				if(VIRTUAL_KEY_UP   == Msg.wCommand)
				{
					bt = (BYTE)Msg.dwParam;
					if(VK_CONTROL == bt)    //Control key up.
					{
						bCtrlDown = FALSE;
					}
				}
			}
		}
	}

__TERMINAL:
	IOManager.WriteFile((__COMMON_OBJECT*)&IOManager,
		hFile,
		(DWORD)(pCurrPos - pDataBuffer),
		pDataBuffer,
		&dwWrittenSize);
	if(pDataBuffer)
	{
		KMemFree(pDataBuffer,KMEM_SIZE_TYPE_ANY,0);
	}
	return;
#else
#endif
}
Ejemplo n.º 13
0
static DWORD type(__CMD_PARA_OBJ* pCmdObj)
{
#ifdef __CFG_SYS_DDF
	HANDLE   hFile = NULL;
	CHAR     Buffer[128];
	DWORD    dwReadSize   = 0;
	DWORD    dwTotalRead  = 0;
	DWORD    i;
	CHAR     FullName[MAX_FILE_NAME_LEN];
	WORD     ch = 0x0700;

	if(pCmdObj->byParameterNum < 2)
	{
		PrintLine("  Please specify the file name to be displayed.");
		goto __TERMINAL;
	}
	strcpy(FullName,FsGlobalData.CurrentDir);
	strcat(FullName,pCmdObj->Parameter[1]);
	ToCapital(FullName);
		
	//Try to open the target file.
	hFile = IOManager.CreateFile((__COMMON_OBJECT*)&IOManager,
		FullName,
		FILE_ACCESS_READ,
		0,
		NULL);
	if(NULL == hFile)
	{
		PrintLine("  Please specify a valid and present file name.");
		goto __TERMINAL;
	}
	//Try to read the target file and display it.
	GotoHome();
	ChangeLine();
	do{
		if(!IOManager.ReadFile((__COMMON_OBJECT*)&IOManager,
			hFile,
			128,
			Buffer,
			&dwReadSize))
		{
			PrintLine("  Can not read the target file.");
			goto __TERMINAL;
		}
		for(i = 0;i < dwReadSize;i ++)
		{
			if('\r' == Buffer[i])
			{
				GotoHome();
				continue;
			}
			if('\n' == Buffer[i])
			{
				ChangeLine();
				continue;
			}
			ch += Buffer[i];
			PrintCh(ch);
			ch = 0x0700;
		}
		dwTotalRead += dwReadSize;
	}while(dwReadSize == 128);

	GotoHome();
	ChangeLine();
	_hx_sprintf(Buffer,"%d byte(s) read.",dwTotalRead);
	PrintLine(Buffer);

__TERMINAL:
	if(NULL != hFile)
	{
		IOManager.CloseFile((__COMMON_OBJECT*)&IOManager,
			hFile);
	}
	return SHELL_CMD_PARSER_SUCCESS;;
#else
	return FS_CMD_FAILED;
#endif
}
Ejemplo n.º 14
0
//Handler for 'cpu' command.
VOID CpuHandler(LPSTR pstr)
{
	GotoHome();
	ChangeLine();
	PrintStr("Cpu Handler called.");
}
Ejemplo n.º 15
0
void PanelView::MessageReceived(BMessage* message)
////////////////////////////////////////////////////////////////////////
{
	switch(message->what)
	{
		case MSG_FILE_SEEK:
			SeekModeOn();
			break;
		case MSG_SEEKING:
			SeekFor(m_SeekTextControl->Text());
			break;
		case MSG_FILE_SEEK_END:
			SeekModeOff();
			break;
		case PATH_MSG_CD_PARENT:
			GotoParent();
			break;
		case PATH_MSG_CD_ROOT:
			GotoRoot();
			break;
		case PATH_MSG_CD_HOME:
			GotoHome();
			break;
		case PATH_MSG_CD_DESKTOP:
			GotoDesktop();
			break;
		case PATH_MSG_CD_DISKS:
			if (m_SeekMode)
				SeekModeOff();
			GotoDisks();
			break;
		case MSG_FILELISTVIEW_SELECTION:
			SelectionChanged();
			break;
		case MSG_PANEL_SELECTED:
			m_LastSelectionTime = real_time_clock_usecs();
			Parent()->Looper()->PostMessage(new BMessage(MSG_UPDATEPANEL_SELECTION));	// To update Panels...

			if (m_SeekMode)
				SeekModeOff();
			break;
		case MSG_ENTER:
			Execute(m_CustomListView->GetSelectedEntry(0));
			break;
		case MSG_SPACE:
			Calculate(m_CustomListView->GetSelectedEntry(0));
			break;
		case MSG_VIEW:	// F3
			View();
			break;
		case MSG_EDIT:	// F4
			Edit();
			break;
		case MSG_COPY:	// F5
			Copy();
			break;
		case MSG_MOVE:
			Move();
			break;
		case MSG_RENAME:	// Shift + F6
			Rename();
			break;
		case MSG_MAKEDIR:	// F7
			MakeDir();
			break;
		case MSG_DELETE:	// F8/Del
			Delete();
			break;
		case MSG_QUIT:	// F10
			be_app->PostMessage(B_QUIT_REQUESTED);
			break;
		case MSG_RELOAD:	// Reload after MkDir, Copy, Move, Delete...
			{
				BString itemname;
				
				// If there is a given name, let's set the selector to it...
				if (message->FindString("ItemName",&itemname)==B_OK)
					Reload(itemname.String());
				else
					Reload();
//				Rescan();
			}
			break;
		case PANELMENU_MSG_SHOWICONS:
			if (m_PanelMenu_ShowIcons->IsMarked())
			{
				m_PanelMenu_ShowIcons->SetMarked(false);
				m_Setting_ShowIcons = false;
				Reload();
			}
			else
			{
				m_PanelMenu_ShowIcons->SetMarked(true);			
				m_Setting_ShowIcons = true;
				Reload();
			}
			break;
		case B_NODE_MONITOR:
			{
				BEntry entry;
				int32 opcode;
				const char *name;
				entry_ref ref;
				node_ref nref;
				
				if (message->FindInt32("opcode", &opcode) == B_OK)
				{
					switch (opcode)
					{
						case B_ENTRY_CREATED:
							message->FindInt32("device", &ref.device);
							message->FindInt64("directory", &ref.directory);
							message->FindString("name", &name);
							ref.set_name(name);
							entry.SetTo(&ref);
							RescanCreated(&entry);
							break;
						case B_ENTRY_REMOVED:
							message->FindInt32("device", &nref.device);
							message->FindInt64("node", &nref.node);
							RescanRemoved(nref);
							break;
						case B_ENTRY_MOVED:	// or renamed...
							message->FindInt32("device", &nref.device);
							message->FindInt64("node", &nref.node);
							RescanRemoved(nref);
							
							message->FindInt32("device", &ref.device);
							message->FindInt64("to directory", &ref.directory);
							message->FindString("name", &name);
							ref.set_name(name);
							entry.SetTo(&ref);
							RescanCreated(&entry);
							break;
						case B_STAT_CHANGED:
							message->FindInt32("device", &nref.device);
							message->FindInt64("node", &nref.node);
							RescanStat(nref);
							break;
						case B_ATTR_CHANGED:
							message->FindInt32("device", &nref.device);
							message->FindInt64("node", &nref.node);
							RescanAttr(nref);
							break;
						case B_DEVICE_MOUNTED:
							if (m_PanelMode==PM_DISKS)
								Reload();
							break;
						case B_DEVICE_UNMOUNTED:
							if (m_PanelMode==PM_DISKS)
								Reload();
							break;
					}
				}
			}
			break;			
		default:
			BView::MessageReceived(message);
	}	
}
Ejemplo n.º 16
0
//
//Print a string at a new line.
//
VOID PrintLine(LPSTR pszStr)
{
	CD_PrintString(pszStr,FALSE);
	GotoHome();
	ChangeLine();
}
Ejemplo n.º 17
0
DWORD Fibonacci(LPVOID lpParam)
{
    //LPSTR lpszParam = (LPSTR)lpParam;
	__CMD_PARA_OBJ* pCmdParaObj               = (__CMD_PARA_OBJ*)lpParam;
    __FIBONACCI_CONTROL_BLOCK ControlBlock[5] = {0};
    HANDLE hThread[5] = {NULL};
    CHAR Buffer[12];
    DWORD dwCounter;
    DWORD dwIndex,i;

	PrintLine("Fibonacci application running...");
	GotoHome();
	ChangeLine();

	if(NULL == pCmdParaObj || pCmdParaObj->byParameterNum < 2)
	{
		return 0;
	}

    dwCounter = 0;
    for(i = 0;i < 5;i ++)
    {     
        dwIndex = 0;
        while(pCmdParaObj->Parameter[1][dwCounter])
		{
			Buffer[dwIndex] =  pCmdParaObj->Parameter[1][dwCounter];
			dwIndex ++;
			dwCounter ++;
		}

        Buffer[dwIndex] = 0;
        Str2Hex(Buffer,&ControlBlock[i].dwInitNum);  //Convert the parameter to integer.

        if(pCmdParaObj->Parameter[1][dwCounter])
		{
			break;
		}
    }

	i = 5;
    for(i;i > 0;i --)
    {
        hThread[i - 1] = CreateKernelThread(
			0,    //Stack size,use default.
            KERNEL_THREAD_STATUS_READY,  //Status.
			PRIORITY_LEVEL_NORMAL,
			CalculateThread,  //Start routine.
			(LPVOID)&ControlBlock[i - 1],
            NULL,
			"FIBONACCI");

        if(NULL == hThread[i - 1])  //Failed to create kernel thread.
        {
            PrintLine("Create kernel thread failed.");
            break;
        }
    }

    //
    //Waiting for the kernel thread to over.
    //
    WaitForThisObject(hThread[0]);
    WaitForThisObject(hThread[1]);
    WaitForThisObject(hThread[2]);
    WaitForThisObject(hThread[3]);
    WaitForThisObject(hThread[4]);

    //
    //Now,we have calculated the fibonacci number,print them out.
    //
    for(i = 0;i < 5;i ++)
    {
        Int2Str(ControlBlock[i].dwInitNum,Buffer);
        PrintStr(Buffer);
        PrintStr("'s result is: ");
        Int2Str(ControlBlock[i].dwResult,Buffer);
        PrintStr(Buffer);
		GotoHome();
        ChangeLine();
    }

    //
    //Close the kernel thread.
    //
    DestroyKernelThread(hThread[0]);
    DestroyKernelThread(hThread[1]);
    DestroyKernelThread(hThread[2]);
    DestroyKernelThread(hThread[3]);
    DestroyKernelThread(hThread[4]);
    
    return 1L;
}