예제 #1
0
static BOOL PspCreateSystemProcess(void)
{
	HANDLE process_handle;
	HANDLE init_thread_handle, idle_thread_handle, process_cutter_handle, thread_cutter_handle;
	HANDLE tmr_thread_handle, sw_task_sw_handle;

	if(!PsCreateProcess(&process_handle)) 
		return FALSE;

	/* create init_thread. */
	if(!PsCreateThread(&init_thread_handle, process_handle, NULL, NULL, DEFAULT_STACK_SIZE, FALSE)) 
		return FALSE;
	HalSetupTaskLink(&PsGetThreadPtr(init_thread_handle)->thread_tss32, TASK_SW_SEG);
	HalWriteTssIntoGdt(&PsGetThreadPtr(init_thread_handle)->thread_tss32, sizeof(TSS_32), INIT_TSS_SEG, FALSE);
	_asm {
		push	ax
		mov		ax, INIT_TSS_SEG
		ltr		ax
		pop		ax
	}

	/* create tmr_int_handler_thread. */
	if(!PsCreateIntThread(&tmr_thread_handle, process_handle, Psp_IRQ_SystemTimer, NULL, DEFAULT_STACK_SIZE)) 
		return FALSE;
	HalWriteTssIntoGdt(&PsGetThreadPtr(tmr_thread_handle)->thread_tss32, sizeof(TSS_32), TMR_TSS_SEG, FALSE);

	/* create soft-task-switching thread */
	if(!PsCreateIntThread(&sw_task_sw_handle, process_handle, PspSoftTaskSW, NULL, DEFAULT_STACK_SIZE)) 
		return FALSE;
	HalWriteTssIntoGdt(&PsGetThreadPtr(sw_task_sw_handle)->thread_tss32, sizeof(TSS_32), SOFT_TS_TSS_SEG, FALSE);

	/* create idle_thread. */
	if(!PsCreateThread(&idle_thread_handle, process_handle, PspIdleThread, NULL, DEFAULT_STACK_SIZE, FALSE)) 
		return FALSE;
	PsSetThreadStatus(idle_thread_handle, THREAD_STATUS_RUNNING);

	HalWriteTssIntoGdt(&PsGetThreadPtr(idle_thread_handle)->thread_tss32, sizeof(TSS_32), TASK_SW_SEG, 
		TRUE); /* LAST PARAMETER SHOULD BE SET WITH 'TRUE'. IMPORTANT!! */
	m_ProcMgrBlk.pt_current_thread = idle_thread_handle; /* IMPORTANT!! */

	/* process cutter & thread cutter */
	if(!PsCreateThread(&process_cutter_handle, process_handle, PspProcessCutterThread, NULL, DEFAULT_STACK_SIZE, FALSE)) 
		return FALSE;
	PsSetThreadStatus(process_cutter_handle, THREAD_STATUS_READY);
	if(!PsCreateThread(&thread_cutter_handle, process_handle, PspThreadCutterThread, NULL, DEFAULT_STACK_SIZE, FALSE)) 
		return FALSE;
	PsSetThreadStatus(thread_cutter_handle, THREAD_STATUS_READY);

	return TRUE;
}
예제 #2
0
파일: process.c 프로젝트: alohays/mylysos
//초기 프로세스와 쓰레드의 생성과 설정
static BOOL PspCreateSystemProcess(void)
{
	HANDLE process_handle;
	HANDLE init_thread_handle, idle_thread_handle, process_cutter_handle, thread_cutter_handle;
	HANDLE tmr_thread_handle, sw_task_sw_handle;

	//메인 프로세스를 생성해주는 PSCreateProcess 함수 호출
	if(!PsCreateProcess(&process_handle)) 
		return FALSE;

	//프로세스를 생성하기 위해 베이스가 될 메인 쓰레드(init 쓰레드) 생성 
	if(!PsCreateThread(&init_thread_handle, process_handle, NULL, NULL, DEFAULT_STACK_SIZE, FALSE)) 
		return FALSE;

	//초기 쓰레드의 백링크(Prev-Link) 설정
	HalSetupTaskLink(&PsGetThreadPtr(init_thread_handle)->thread_tss32, TASK_SW_SEG);
	//초기 쓰레드의 TSS를 GDT내에 설정
	HalWriteTssIntoGdt(&PsGetThreadPtr(init_thread_handle)->thread_tss32, sizeof(TSS_32), INIT_TSS_SEG, FALSE);
	_asm {
		push	ax
		mov		ax, INIT_TSS_SEG
		ltr		ax
		pop		ax
	}

	if(!PsCreateIntThread(&tmr_thread_handle, process_handle, Psp_IRQ_SystemTimer, NULL, DEFAULT_STACK_SIZE))
		return FALSE;
	HalWriteTssIntoGdt(&PsGetThreadPtr(tmr_thread_handle)->thread_tss32, sizeof(TSS_32), TMR_TSS_SEG, FALSE);

	if(!PsCreateIntThread(&sw_task_sw_handle, process_handle, PspSoftTaskSW, NULL, DEFAULT_STACK_SIZE))
		return FALSE;
	HalWriteTssIntoGdt(&PsGetThreadPtr(sw_task_sw_handle)->thread_tss32, sizeof(TSS_32), SOFT_TS_TSS_SEG, FALSE);

	if(!PsCreateThread(&idle_thread_handle, process_handle, PspIdleThread, NULL, DEFAULT_STACK_SIZE, FALSE))
		return FALSE;
	PsSetThreadStatus(idle_thread_handle, THREAD_STATUS_RUNNING);

	HalWriteTssIntoGdt(&PsGetThreadPtr(idle_thread_handle)->thread_tss32, sizeof(TSS_32), TASK_SW_SEG,
		TRUE);
	m_ProcMgrBlk.pt_current_thread = idle_thread_handle;

	if(!PsCreateThread(&process_cutter_handle, process_handle, PspProcessCutterThread, NULL, DEFAULT_STACK_SIZE, FALSE))
		return FALSE;
	PsSetThreadStatus(process_cutter_handle, THREAD_STATUS_READY);
	if(!PsCreateThread(&thread_cutter_handle, process_handle, PspThreadCutterThread, NULL, DEFAULT_STACK_SIZE, FALSE))
		return FALSE;
	PsSetThreadStatus(thread_cutter_handle, THREAD_STATUS_READY);
		
	return TRUE;
}
예제 #3
0
파일: process.c 프로젝트: alohays/mylysos
//태스크 스위칭 방법 중 하나
static void PspSetupTaskSWEnv(void)
{
	HANDLE current_thread, next_thread;

	current_thread = PsGetCurrentThread();

	next_thread = PspFindNextThreadScheduled();

	if(PsGetThreadPtr(current_thread)->thread_status == THREAD_STATUS_TERMINATED) {
		if(PsGetThreadPtr(current_thread)->auto_delete) {
			PsDeleteThread(current_thread);
		}
	} else if(PsGetThreadPtr(current_thread)->thread_status == THREAD_STATUS_RUNNING) {
		PsGetThreadPtr(current_thread)->thread_status = THREAD_STATUS_READY;
	}

	if(current_thread != next_thread && next_thread != NULL) {
		HalWriteTssIntoGdt(&PsGetThreadPtr(next_thread)->thread_tss32, sizeof(TSS_32), TASK_SW_SEG, TRUE);
		PsGetThreadPtr(next_thread)->thread_status = THREAD_STATUS_RUNNING;
	}
}
예제 #4
0
static void PspSetupTaskSWEnv(void)
{
	HANDLE current_thread, next_thread;

	/* get threads */
	current_thread = PsGetCurrentThread();
	next_thread = PspFindNextThreadScheduled();	/* at this time, current thread is changed with new thing */

	if(PsGetThreadPtr(current_thread)->thread_status == THREAD_STATUS_TERMINATED) {
		/* auto delete? */
		if(PsGetThreadPtr(current_thread)->auto_delete) {
			PsDeleteThread(current_thread);
		}
	} else if(PsGetThreadPtr(current_thread)->thread_status == THREAD_STATUS_RUNNING) {
		PsGetThreadPtr(current_thread)->thread_status = THREAD_STATUS_READY;
	}

	/* task switching */
	if(current_thread != next_thread && next_thread != NULL) {
		HalWriteTssIntoGdt(&PsGetThreadPtr(next_thread)->thread_tss32, sizeof(TSS_32), TASK_SW_SEG, TRUE);
		PsGetThreadPtr(next_thread)->thread_status = THREAD_STATUS_RUNNING;
	}
}