www.pudn.com > LFYOS.zip > init.c


#include"kernel.h" 
int idle_driver(struct file_system_call_parameter *par) 
{ 
	return (-1); 
} 
int os_init() 
{ 
	int i,j; 
	struct return_stack *rt; 
 
	init_file_information(); 
 
	for(i=0;iprocess[i].start_point)); 
		os->process[i].driver=idle_driver; 
		os->process[i].priority=0; 
		os->process[i].semaphore=-1; 
		os->process[i].enter_thread_number=0; 
		os->process[i].id=0; 
		os->process[i].max_thread_number=0; 
		os->process[i].thread_number=0; 
		os->process[i].thread_ring=(-1); 
		os->process[i].max_semaphore_number=0; 
		os->process[i].semaphore_number=0; 
		os->process[i].semaphore_ring=(-1); 
		RESET_CAPABILITY(os->process[i].capability); 
	} 
	os->process[0].max_thread_number=THREAD_NUMBER-1; 
	os->process[0].thread_number=THREAD_NUMBER-1; 
	os->process[0].thread_ring=1; 
	os->process[0].max_semaphore_number=SEMAPHORE_NUMBER-1; 
	os->process[0].semaphore_number=SEMAPHORE_NUMBER-1; 
	os->process[0].semaphore_ring=1; 
 
	os->process[1].enter_thread_number=1; 
	os->process[1].max_thread_number=1; 
	os->process[1].thread_number=1; 
	os->process[1].thread_ring=0; 
	os->process[1].semaphore_number=0; 
	os->process[1].max_semaphore_number=1+MEMORY_BODY_NUMBER; 
 
	for(i=0;isemaphore[i].value=0; 
		os->semaphore[i].process=0; 
		os->semaphore[i].thread_ring=-1; 
		os->semaphore[i].front=i-1; 
		os->semaphore[i].back=i+1; 
		RESET_CAPABILITY(os->semaphore[i].capability); 
		os->semaphore[i].heap=i; 
		os->semaphore[i].v_value=0; 
		os->semaphore_heap[i].semaphore_id=i; 
		SET_MOST_TIME(os->semaphore[i].first); 
		SET_MINIMAL_STEP(os->semaphore[i].step); 
	} 
 
	os->semaphore[SEMAPHORE_NUMBER-1].back=1; 
	os->semaphore[1].front=SEMAPHORE_NUMBER-1; 
 
	os->semaphore[0].value=1-THREAD_NUMBER; 
	os->semaphore[0].thread_ring=THREAD_NUMBER-1; 
	os->semaphore[0].front=0;os->semaphore[0].back=0; 
 
	for(i=0;ithread[i].state=SLEEP; 
 
		os->thread[i].priority=0; 
		os->thread[i].set_v_operation_result_flag=FALSE; 
		os->thread[i].heap=-1; 
		os->thread[i].process=0; 
		os->thread[i].pro_front=i-1; 
		os->thread[i].pro_back=i+1; 
		os->thread[i].semaphore=-1; 
		os->thread[i].sleep_semaphore=0; 
		os->thread[i].sem_front=i-1; 
		os->thread[i].sem_back=i+1; 
	 
		os->thread[i].return_stack_top=0; 
		for(j=RETURN_BLOCK_NUMBER-1;j>=0;j--){ 
			rt=&(os->thread[i].return_stack[j]); 
			RESET_THREAD_ENVIRONMENT(rt->environment); 
			rt->current_process=0; 
			rt->process_id=0; 
			rt->process_p_flag=TRUE; 
			RESET_EXCEPTION_ITEM(rt->exception); 
			RESET_PHYSICAL_BLOCK((rt->physical_block),(-1)); 
		} 
	}; 
	os->thread[1].sem_front=THREAD_NUMBER-1; 
	os->thread[THREAD_NUMBER-1].sem_back=1; 
 
	os->thread[1].pro_front=THREAD_NUMBER-1; 
	os->thread[THREAD_NUMBER-1].pro_back=1; 
 
	os->thread[0].state=RUN; 
	os->thread[0].process=1; 
	os->thread[0].heap=0; 
	os->thread[0].cpu_id=0; 
	os->thread[0].sleep_semaphore=-1; 
	os->thread[0].sem_front=-1; 
	os->thread[0].sem_back=-1; 
	os->thread[0].pro_front=0; 
	os->thread[0].pro_back=0; 
	os->thread[0].return_stack_top=1; 
	rt=&(os->thread[0].return_stack[0]); 
	rt->current_process=1; 
	rt->process_p_flag=TRUE; 
	 
	os->thread_heap.run_thread_number=1; 
	os->thread_heap.ready_thread_number=0; 
	os->thread_heap.run_heap[0].thread=0; 
 
	for(i=0;ivirtual_cpu.used_cpu[i].thread_id=(-1); 
		RESET_CPU_INFORMATION(os->virtual_cpu.used_cpu[i]); 
	} 
 
	os->virtual_cpu.used_cpu[0].thread_id=0; 
	for(i=1;ivirtual_cpu.free_cpu[i-1].cpu_id=i; 
	os->virtual_cpu.free_cpu_top=VIRTUAL_CPU_NUMBER-1; 
	 
	CLEAR_TIME(os->current_time); 
 
	RESET_CAPABILITY(os->system_capability); 
	{ 
		struct thread *t; 
		struct return_stack *rt; 
 
		t=&(os->thread[0]); 
		rt=&(t->return_stack[t->return_stack_top-1]); 
 
		t->semaphore=allocate_semaphore(t->process,0, 
			&(os->process[t->process].capability), 
			&(os->process[rt->current_process].capability)); 
		if(t->semaphore>0) 
			os->semaphore[t->semaphore].thread_id=0; 
		for(i=0;isystem_file[i].semaphore_id 
			=allocate_semaphore(t->process,1, 
				&(os->system_capability), 
				&(os->system_capability)); 
		} 
			 
	} 
	return 0; 
}