Esempio n. 1
0
void
os_init_cont(void) {
   /* Reset the GDT. Although user processes in Nanos run in Ring 0,
      they have their own virtual address space. Therefore, the
      old GDT located in physical address 0x7C00 cannot be used again. */
   init_segment();

   /* Initialize the serial port. After that, you can use printk() */
   init_serial();

   /* Set up interrupt and exception handlers,
      just as we did in the game. */
   init_idt();

   /* Initialize the intel 8259 PIC. */
   init_intr();

   /* Initialize processes. You should fill this. */
   init_proc();

   welcome();

   sti();

   /* This context now becomes the idle process. */
   while (1) {
      wait_intr();
   }
}
Esempio n. 2
0
/* 游戏主循环。
 * 在初始化工作结束后,main函数就跳转到主循环执行。
 * 在主循环执行期间随时会插入异步的中断。时钟中断最终调用timer_event,
 * 键盘中断最终调用keyboard_event。中断处理完成后将返回主循环原位置继续执行。
 *
 * tick是时钟中断中维护的信号,数值含义是“系统到当前时刻已经发生过的时钟中断数”
 * HZ是时钟控制器硬件每秒产生的中断数,在include/device/timer.h中定义
 * now是主循环已经正确处理的时钟中断数,即游戏已经处理到的物理时间点
 * */
void
main_loop(void) {
	int now = 0, target;
	int num_draw = 0;
	bool redraw;

	while (true) {
		wait_intr();
		cli();
		if (now == tick) {
			sti();
			continue;
		}
		assert(now < tick);
		target = tick; /* now总是小于tick,因此我们需要“追赶”当前的时间 */
		sti();

		redraw = false;
		while (update_keypress())
			;

		/* 依次模拟已经错过的时钟中断。一次主循环如果执行时间长,期间可能到来多次时钟中断,
		 * 从而主循环中维护的时钟可能与实际时钟相差较多。为了维持游戏的正常运行,必须补上
		 * 期间错过的每一帧游戏逻辑。 */
		while (now < target) { 
			/* 每隔一定时间产生一个新的字符 */
			if (now % (HZ / CHARACTER_PER_SECOND) == 0) {
				create_new_letter();
			} 
			/* 每隔一定时间更新屏幕上字符的位置 */
			if (now % (HZ / UPDATE_PER_SECOND) == 0) {
				update_letter_pos();
			}
			/* 每隔一定时间需要刷新屏幕。注意到这里实现了“跳帧”的机制:假设
			 *   HZ = 1000, FPS = 100, now = 10, target = 1000
			 * 即我们要模拟990个时钟中断之间发生的事件,其中包含了9次屏幕更新,
			 * 但redraw flag只被置一次。 */

			/* 以上是余大神的解释,但我觉得怎么应该是: */
			/* 即我们要模拟990个时钟中断,其中redraw flag被重置了99次(应该更新99次), */
			/* 但实际上屏幕只更新了一次 */
			if (now % (HZ / FPS) == 0) {
				redraw = true;
			}
			/* 更新fps统计信息 */
			if (now % (HZ / 2) == 0) {
				int now_fps = num_draw * 2 + 1;
				if (now_fps > FPS) now_fps = FPS;
				set_fps(now_fps);
				num_draw = 0;
			}
			now ++;
		}

		if (redraw) { /* 当需要重新绘图时重绘 */
			num_draw ++;
			redraw_screen();
		}
	}
}
Esempio n. 3
0
void sleep(void){
	ListHead *tmp;

/*    list_foreach(tmp, &current->list) {
        printk("bcurrent: %x\n", tmp);
    }*/
    tmp=&current->list;
	list_del(&current->list);

/*    list_foreach(tmp, &current->list) {
        printk("acurrent: %x\n", tmp);
    }*/
	list_add_after(&block, tmp);
	wait_intr(); 
	/*asm volatile("int $0x80"); */
}
Esempio n. 4
0
File: main.c Progetto: zzt93/os-lab1
void
os_init_cont(void) {
    /* Reset the GDT. Although user processes in Nanos run in Ring 0,
       they have their own virtual address space. Therefore, the
       old GDT located in physical address 0x7C00 cannot be used again. */
    init_segment();

    /* Initialize the serial port. After that, you can use printk() */
    init_serial();

    /* Set up interrupt and exception handlers,
       just as we did in the game. */
    init_idt();

    /* Initialize the intel 8259 PIC. */
    //The Intel 8259 is a Programmable Interrupt Controller (PIC)
    init_intr();

    /**
       initialize kmalloc -- have to initialize it before init
       process, for using it in allocating memory for PCB
    */
    init_kmalloc();
    // make it NOINTR, can receive msg, can schedule
    init_idle();

    NOINTR;

    /**
       init_driver() have to before init_file_system() for FM have
       to send message to `ide` to read file system
     */
    init_driver();
    init_manager();
    NOINTR;
    init_error_msg();
    // init_proc() and init_manager() can replace??
    // solved by split set count_of_lock out of init_proc();

    //more_frequent();
    // init empty thread
    init_proc_test();

    // here is to initialize shell process, which must later
    // than init_manager -- for it will send message to
    // managers
    //ram_user_process();


    // @checked: move from locked state to unlocked state
    init_file_system();

    unlock(); // set interrupt enabled
    INTR;

    /**
       init_file_system() have to before init_proc()
       for init_proc() will using the `default_cwd` which is
       initialized by FM
    */
    /* Initialize the state of process idle, ie the running
       process for set up right lock num to avoid other
       initialization enable the interrupt and cause problem
    */

    // @checked: move from locked state to unlocked state
    welcome();

    user_process();
    // set idle not to using cpu time
    // for it is originally set to sleep when send message
    current->state = SLEEPED;


    /* This context now becomes the idle process. */
    while (1) {
        printk("!");
        wait_intr();
    }
}
Esempio n. 5
0
void
abort(const char *file, int line) {
	cli();
	printk("\n\nFatal error (assertion failure) at %s:%d\n", file, line);
	wait_intr();
}
Esempio n. 6
0
void
panic(const char *str) {
	cli();
	printk("\n\nFatal error (kernel panic): %s\n", str);
	wait_intr();
}