Example #1
0
void kernel_c(){
	//init basic data&struct
	heap_init();
	proc_init();
	init_fs();
	mem_entity[0]='G';
	mem_entity[1]='M';
	mem_entity[2]='K';
	mem_entity[3]='B';
	k_screen_reset();
	detect_cpu();
	oprintf("detecting cpu...cpu identify:%s\n",cpu_string);
//	oprintf("mm init..\nring0_pgdir:%x,ring0_pgtbl:%x,base_proc_pgdir:%x,addr_kernel_info:%x,pages:%x\n",RING0_PGDIR,RING0_PGTBL,BASE_PROC_PGDIR,ADDR_KERNEL_INFO,PAGES);
	global_equal_map();
	__asm__("mov $0x101000,%eax\t\n"
			"mov %eax,%cr3\t\n"
			"mov %cr0,%eax\t\n"
			"or $0x80000000,%eax\t\n"
			"mov %eax,%cr0\t\n"
			);
	oprintf("global page-mapping for kernel built..open MMU\n");
	create_kernel_process((int)&idle,9,0xffff,"idle",0);	//pid must =0
	create_kernel_process((int)hs,2,0xffff,"hs",1);//hs的时间片要非常多,保证在下一轮时间片重置之前不会被挂起 ERR:pid must =1
	create_kernel_process((int)fs_ext,4,10,"fs_ext",1);//pid must =2

	create_kernel_process((int)mm,3,10,"mm",1);//ERR mm has great prio,because it shall run and prepare condition for other process
	create_kernel_process((int)tty,5,10,"tty",1);
	create_kernel_process((int)&p1,8,10,"p1",1);
//	ofork(t1,9,15,"t1",1);
//	ofork(t2,9,5,"t2",1);
//	ofork((int)&p2,7,5,"p2",3);
	oprintf("basic process ofork done..now open IRQ,proc-dispatch begin\n");
	__asm__("sti");
	while(1);//内核陷入死循环,等待第一次时钟中断
}
Example #2
0
void tty(void){
	oprintf("try to mount device1:partation:3:%s\n",mount("/mnt/",1,3)?"success":"failed");
	int crt_start;
	__asm__("cli");
	loadbuf=kmalloc(SIZE_LOAD_BUF);
	oprintf("tty running..welcome^.^\n");
	buff=kmalloc(23);
	for(int j=0;j<0;j++){
		oprintf("j=%u,i will do open\n",j);
//		int fd=open("/mnt/home/wws/dimg",0);
		int fd=open("/mnt/short");
		oprintf("fd:%u,inode:%u\n",fd,fd_table[fd].inode);
		int newseek=lseek(fd,-2,2);
		int r_bytes=read(fd,tmp,7);
		oprintf("r_bytes:%u,newseek:%u\n",r_bytes,newseek);
//		while(1);
	}
	while(1){
new_prompt:
		reset_cmd_asciis();
		memsetw((u16*)loadbuf,SIZE_LOAD_BUF/2,0);
		oprintf("#   ");
wait_input:
		while(1){
			unsigned ascii=getchar();
			switch(ascii){
				case 128://ctrl+l
					k_screen_reset();
					goto new_prompt;
				case 129://ctrl+c
					kill(front_pid);
					oprintf("^C\n");
					goto new_prompt;
				case 130://ctrl+u
					crt_start=get_start();
					set_start(crt_start>=80?crt_start-80:crt_start);
					goto wait_input;
				case 131://ctrl+d
					crt_start=get_start();
					set_start(crt_start<(80*24*4-1)?crt_start+80:crt_start);
					goto wait_input;
			}
			oprintf("%c",ascii);//oprintf函数有能力打印控制字符,但更多的ctrl,shift组合还要跟进
			if(ascii=='\n'){//回车符执行命令
				parse_cmd_asciis();
				break;
			}
			//执行到这儿,说明是普通输入,写入cmd_asciis
			write_cmd_asciis(ascii);
		}
	}
}