• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ cons_getc函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中cons_getc函数的典型用法代码示例。如果您正苦于以下问题:C++ cons_getc函数的具体用法?C++ cons_getc怎么用?C++ cons_getc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了cons_getc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: trap_dispatch

/* trap_dispatch - dispatch based on what type of trap occurred */
static void trap_dispatch(struct trapframe *tf) {
	char c;

	switch (tf->tf_trapno) {
	case IRQ_OFFSET + IRQ_TIMER:
		/* LAB1 YOUR CODE : STEP 3 */
		/* handle the timer interrupt */
		/* (1) After a timer interrupt, you should record this event using a global variable (increase it), such as ticks in kern/driver/clock.c
		 * (2) Every TICK_NUM cycle, you can print some info using a funciton, such as print_ticks().
		 * (3) Too Simple? Yes, I think so!
		 */
		if(++ticks % TICK_NUM == 0) {
			print_ticks();
		}
		break;
	case IRQ_OFFSET + IRQ_COM1:
		c = cons_getc();
		cprintf("serial [%03d] %c\n", c, c);
		break;
	case IRQ_OFFSET + IRQ_KBD:
		c = cons_getc();
		cprintf("kbd [%03d] %c\n", c, c);
		break;
		//LAB1 CHALLENGE 1 : YOUR CODE you should modify below codes.
	case T_SWITCH_TOU:
		if(tf->tf_cs != USER_CS) {
			user_stack = *tf;
			user_stack.tf_cs = USER_CS;
			user_stack.tf_ds = USER_DS;
			user_stack.tf_ss = USER_DS;
			user_stack.tf_es = USER_DS;
			user_stack.tf_esp = (uint32_t)tf + sizeof(struct trapframe) - 8;
			user_stack.tf_eflags |= FL_IOPL_MASK;
			*((uint32_t *)tf - 1) = (uint32_t)&user_stack;
		}
		break;
	case T_SWITCH_TOK:
		if(tf->tf_cs != KERNEL_CS) {
			tf->tf_cs = KERNEL_CS;
			tf->tf_ds = KERNEL_DS;
			tf->tf_es = KERNEL_DS;
			tf->tf_eflags &= ~FL_IOPL_MASK;
			struct trapframe* k = (struct trapframe*)(tf->tf_esp - (sizeof(struct trapframe) - 8));
			memmove(k, tf, sizeof(struct trapframe) -8);
			*((uint32_t *)tf - 1) = (uint32_t)k;

		}
		break;
	case IRQ_OFFSET + IRQ_IDE1:
	case IRQ_OFFSET + IRQ_IDE2:
		/* do nothing */
		break;
	default:
		// in kernel, it must be a mistake
		if ((tf->tf_cs & 3) == 0) {
			print_trapframe(tf);
			panic("unexpected trap in kernel.\n");
		}
	}
}
开发者ID:maye9999,项目名称:ucore_os_lab,代码行数:61,代码来源:trap.c


示例2: trap_dispatch

static void
trap_dispatch(struct trapframe *tf) {
    char c;

    int ret;

    switch (tf->tf_trapno) {
    case T_PGFLT:  //page fault
        if ((ret = pgfault_handler(tf)) != 0) {
            print_trapframe(tf);
            panic("handle pgfault failed. %e\n", ret);
        }
        break;
    case IRQ_OFFSET + IRQ_TIMER:
#if 0
    LAB3 : If some page replacement algorithm(such as CLOCK PRA) need tick to change the priority of pages, 
    then you can add code here. 
#endif
        /* LAB1 YOUR CODE : STEP 3 */
        /* handle the timer interrupt */
        /* (1) After a timer interrupt, you should record this event using a global variable (increase it), such as ticks in kern/driver/clock.c
         * (2) Every TICK_NUM cycle, you can print some info using a funciton, such as print_ticks().
         * (3) Too Simple? Yes, I think so!
         */

 ticks ++;
        if (ticks % TICK_NUM == 0) {
            print_ticks();
        }
        break;
    case IRQ_OFFSET + IRQ_COM1:
        c = cons_getc();
        cprintf("serial [%03d] %c\n", c, c);
        break;
    case IRQ_OFFSET + IRQ_KBD:
        c = cons_getc();
        cprintf("kbd [%03d] %c\n", c, c);
        break;
    //LAB1 CHALLENGE 1 : YOUR CODE you should modify below codes.
    case T_SWITCH_TOU:
    case T_SWITCH_TOK:
        panic("T_SWITCH_** ??\n");
        break;
    case IRQ_OFFSET + IRQ_IDE1:
    case IRQ_OFFSET + IRQ_IDE2:
        /* do nothing */
        break;
    default:
        // in kernel, it must be a mistake
        if ((tf->tf_cs & 3) == 0) {
            print_trapframe(tf);
            panic("unexpected trap in kernel.\n");
        }
    }
}
开发者ID:huhanGitHub,项目名称:Ucore,代码行数:55,代码来源:trap.c


示例3: trap_dispatch

/* trap_dispatch - dispatch based on what type of trap occurred */
static void
trap_dispatch(struct trapframe *tf) {
    char c;

    switch (tf->tf_trapno) {
    case IRQ_OFFSET + IRQ_TIMER:
        /* LAB1 2012012139 : STEP 3 */
        /* handle the timer interrupt */
        /* (1) After a timer interrupt, you should record this event using a global variable (increase it), such as ticks in kern/driver/clock.c
         * (2) Every TICK_NUM cycle, you can print some info using a funciton, such as print_ticks().
         * (3) Too Simple? Yes, I think so!
         */
        ++ticks;
        if (ticks == TICK_NUM) {
          print_ticks();
          ticks = 0;
        }
        break;
    case IRQ_OFFSET + IRQ_COM1:
        c = cons_getc();
        cprintf("serial [%03d] %c\n", c, c);
        break;
    case IRQ_OFFSET + IRQ_KBD:
        c = cons_getc();
        cprintf("kbd [%03d] %c\n", c, c);
        break;
    //LAB1 CHALLENGE 1 : 2012012139 you should modify below codes.
    case T_SWITCH_TOU:
        tf->tf_cs = USER_CS;
        tf->tf_ds = USER_DS;
        tf->tf_es = USER_DS;
        tf->tf_ss = USER_DS;
        // 改变IO输出所需要的权限,使得用户可以写
        tf->tf_eflags |= 0x3000;
        break;
    case T_SWITCH_TOK:
        tf->tf_cs = KERNEL_CS;
        tf->tf_ds = KERNEL_DS;
        tf->tf_es = KERNEL_DS;
        // tf->tf_ss = KERNEL_DS;
        // panic("T_SWITCH_** ??\n");
        break;
    case IRQ_OFFSET + IRQ_IDE1:
    case IRQ_OFFSET + IRQ_IDE2:
        /* do nothing */
        break;
    default:
        // in kernel, it must be a mistake
        if ((tf->tf_cs & 3) == 0) {
            print_trapframe(tf);
            panic("unexpected trap in kernel.\n");
        }
    }
}
开发者ID:gaoboallen,项目名称:ucore_lab,代码行数:55,代码来源:trap.c


示例4: getchar

/* getchar - reads a single non-zero character from stdin */
int
getchar(void) {
    int c;
    while ((c = cons_getc()) == 0)
        /* do nothing */;
    return c;
}
开发者ID:lhh520,项目名称:os-4-risc-v,代码行数:8,代码来源:stdio.c


示例5: serial_int_handler

static int serial_int_handler(int irq, void * data)
{
  extern void dev_stdin_write(char c);
  char c = cons_getc();
  dev_stdin_write(c);
  return 0;
}
开发者ID:PungiZhang,项目名称:ucore_plus-next,代码行数:7,代码来源:goldfish_uart.c


示例6: trap_dispatch

/* trap_dispatch - dispatch based on what type of trap occurred */
static void
trap_dispatch(struct trapframe *tf) {
    char c;

    switch (tf->tf_trapno) {
    case T_DEBUG:
    case T_BRKPT:
        debug_monitor(tf);
        break;
    case IRQ_OFFSET + IRQ_TIMER:
        ticks ++;
        if (ticks % TICK_NUM == 0) {
            cprintf("%d ticks\n",TICK_NUM);
        }
        break;
    case IRQ_OFFSET + IRQ_COM1:
    case IRQ_OFFSET + IRQ_KBD:
        if ((c = cons_getc()) == 13) {
            debug_monitor(tf);
        }
        else {
            cprintf("%s [%03d] %c\n",
                    (tf->tf_trapno != IRQ_OFFSET + IRQ_KBD) ? "serial" : "kbd", c, c);
        }
        break;
    default:
        // in kernel, it must be a mistake
        if ((tf->tf_cs & 3) == 0) {
            print_trapframe(tf);
            panic("unexpected trap in kernel.\n");
        }
    }
}
开发者ID:jefjin,项目名称:ucore,代码行数:34,代码来源:trap.c


示例7: cons_io

// Synchronize the root process's console special files
// with the actual console I/O device.
bool
cons_io(void)
{
	int num_io = 0;

	// Get output file
	fileinode *fi = &files->fi[FILEINO_CONSOUT];
	int c;
	// spinlock_acquire(&cons_lock);
	while(cons_out_pos < fi->size) {
		c = ((char*)FILEDATA(FILEINO_CONSOUT))[cons_out_pos];
		cons_putc(c);
		num_io++;
		cons_out_pos++;
	}
	// spinlock_release(&cons_lock);
	// Input file
	fi = &files->fi[FILEINO_CONSIN];
	// Read from console
	while(fi->size <= FILE_MAXSIZE && (c = cons_getc())) {
		// And appened to CONSIN
		((char*)FILEDATA(FILEINO_CONSIN))[fi->size++] = c;
		num_io++;
	}

	return num_io;
}
开发者ID:khanotations,项目名称:pios,代码行数:29,代码来源:cons.c


示例8: irq_handler

void irq_handler(){
  uint32_t pending = inw(VIC_VBASE+INTERRUPT_STATUS);
  uint32_t irq = 0;
  while(pending > 0){
    irq = inw(VIC_VBASE+INTERRUPT_NUMBER);
    if(actions[irq].handler){
      (*actions[irq].handler)(irq, actions[irq].opaque);
    }else{
      pic_disable(irq);
    }
    pending = inw(VIC_VBASE+INTERRUPT_STATUS);
  }
#if 0
  if(status & (1<<TIMER0_IRQ)){
    //kprintf("@");
    ticks++;
		//assert(pls_read(current) != NULL);
    run_timer_list();
    clock_clear();
  }
  if( status & (1<<UART_IRQ) ){
    //if ((c = cons_getc()) == 13) {
    //  debug_monitor(tf);
    //}
    //else {
      extern void dev_stdin_write(char c);
      char c = cons_getc();
      dev_stdin_write(c);
    //}
    //kprintf("#");
    serial_clear();
  }
#endif
}
开发者ID:chyyuu,项目名称:ucore-arch-arm,代码行数:34,代码来源:picirq.c


示例9: trap_dispatch

/* trap_dispatch - dispatch based on what type of trap occurred */
static void
trap_dispatch(struct trapframe *tf) {
    char c;

    switch (tf->tf_trapno) {
    case IRQ_OFFSET + IRQ_TIMER:
        ticks ++;
        if (ticks % TICK_NUM == 0) {
            print_ticks();
        }
        break;
    case IRQ_OFFSET + IRQ_COM1:
        c = cons_getc();
        cprintf("serial [%03d] %c\n", c, c);
        break;
    case IRQ_OFFSET + IRQ_KBD:
        c = cons_getc();
        cprintf("kbd [%03d] %c\n", c, c);
        break;
    case T_SWITCH_TOU:
        if (tf->tf_cs != USER_CS) {
            tf->tf_cs = USER_CS;
            tf->tf_ds = tf->tf_es = USER_DS;
            tf->tf_ss = USER_DS;
            // set eflags, make sure ucore can use io under user mode.
            // if CPL > IOPL, then cpu will generate a general protection.
            tf->tf_rflags |= FL_IOPL_MASK;
        }
        break;
    case T_SWITCH_TOK:
        if (tf->tf_cs != KERNEL_CS) {
            tf->tf_cs = KERNEL_CS;
            tf->tf_ds = tf->tf_es = KERNEL_DS;
            tf->tf_ss = KERNEL_DS;
            tf->tf_rflags &= ~FL_IOPL_MASK;
        }
        break;
    default:
        // in kernel, it must be a mistake
        if ((tf->tf_cs & 3) == 0) {
            print_trapframe(tf);
            panic("unexpected trap in kernel.\n");
        }
    }
}
开发者ID:spinlock,项目名称:ucore,代码行数:46,代码来源:trap.c


示例10: trap_dispatch

static void
trap_dispatch(struct trapframe *tf) {
    char c;

    int ret;

    switch (tf->tf_trapno) {
    case T_DEBUG:
    case T_BRKPT:
        debug_monitor(tf);
        break;
    case T_PGFLT:
        if ((ret = pgfault_handler(tf)) != 0) {
            print_trapframe(tf);
            if (current == NULL) {
                panic("handle pgfault failed. %e\n", ret);
            }
            else {
                if (trap_in_kernel(tf)) {
                    panic("handle pgfault failed in kernel mode. %e\n", ret);
                }
                cprintf("killed by kernel.\n");
                do_exit(-E_KILLED);
            }
        }
        break;
    case T_SYSCALL:
        syscall();
        break;
    case IRQ_OFFSET + IRQ_TIMER:
        ticks ++;
        assert(current != NULL);
        run_timer_list();
        break;
    case IRQ_OFFSET + IRQ_COM1:
    case IRQ_OFFSET + IRQ_KBD:
        if ((c = cons_getc()) == 13) {
            debug_monitor(tf);
        }
        else {
            cprintf("%s [%03d] %c\n",
                    (tf->tf_trapno != IRQ_OFFSET + IRQ_KBD) ? "serial" : "kbd", c, c);
        }
        break;
    case IRQ_OFFSET + IRQ_IDE1:
    case IRQ_OFFSET + IRQ_IDE2:
        /* do nothing */
        break;
    default:
        print_trapframe(tf);
        if (current != NULL) {
            cprintf("unhandled trap.\n");
            do_exit(-E_KILLED);
        }
        panic("unexpected trap in kernel.\n");
    }
}
开发者ID:jefjin,项目名称:ucore,代码行数:57,代码来源:trap.c


示例11: trap_dispatch

/* trap_dispatch - dispatch based on what type of trap occurred */
static void
trap_dispatch(struct trapframe *tf) {
    char c;

    switch (tf->tf_trapno) {
    case IRQ_OFFSET + IRQ_TIMER:
        /* LAB1 YOUR CODE : STEP 3 */
        /* handle the timer interrupt */
        /* (1) After a timer interrupt, you should record this event using a global variable (increase it), such as ticks in kern/driver/clock.c
         * (2) Every TICK_NUM cycle, you can print some info using a funciton, such as print_ticks().
         * (3) Too Simple? Yes, I think so!
         */
        ticks++;
        if (ticks % TICK_NUM == 0)
        {
		    print_ticks();
        }
        break;
    case IRQ_OFFSET + IRQ_COM1:
        c = cons_getc();
        cprintf("serial [%03d] %c\n", c, c);
        break;
    case IRQ_OFFSET + IRQ_KBD:
        c = cons_getc();
        cprintf("kbd [%03d] %c\n", c, c);
        break;
    //LAB1 CHALLENGE 1 : YOUR CODE you should modify below codes.
    case T_SWITCH_TOU:
    case T_SWITCH_TOK:
        panic("T_SWITCH_** ??\n");
        break;
    case IRQ_OFFSET + IRQ_IDE1:
    case IRQ_OFFSET + IRQ_IDE2:
        /* do nothing */
        break;
    default:
        // in kernel, it must be a mistake
        if ((tf->tf_cs & 3) == 0) {
            print_trapframe(tf);
            panic("unexpected trap in kernel.\n");
        }
    }
}
开发者ID:greent2008,项目名称:os_lab,代码行数:44,代码来源:trap.c


示例12: serial_int_handler

void serial_int_handler(void *opaque)
{
  unsigned char id = inb(COM1+COM_IIR);
  if(id & 0x01)
    return ;
  //int c = serial_proc_data();
  int c = cons_getc(c);
  extern void dev_stdin_write(char c);
  dev_stdin_write(c);
}
开发者ID:aaeviru,项目名称:ucore_plus,代码行数:10,代码来源:console.c


示例13: arch_init

void arch_init()
{
	pci_init();
#ifdef __CONFIG_ENABLE_MPTABLES__
	mptables_parse();
	ioapic_init(); // MUST BE AFTER PCI/ISA INIT!
	// TODO: move these back to regular init.  requires fixing the 
	// __CONFIG_NETWORKING__ inits to not need multiple cores running.
#endif
	// this returns when all other cores are done and ready to receive IPIs
	#ifdef __CONFIG_SINGLE_CORE__
		smp_percpu_init();
	#else
		smp_boot();
	#endif
	proc_init();

	/* EXPERIMENTAL NETWORK FUNCTIONALITY
	 * To enable, define __CONFIG_NETWORKING__ in your Makelocal
	 * If enabled, will load the rl8168 driver (if device exists)
	 * and will a boot into userland matrix, so remote syscalls can be performed.
 	 * If in simulation, will do some debugging information with the ne2k device
	 *
	 * Note: If you use this, you should also define the mac address of the 
	 * teathered machine via USER_MAC_ADDRESS in Makelocal.
	 *
	 * Additionally, you should have a look at the syscall server in the tools directory
	 */
	#ifdef __CONFIG_NETWORKING__
	#ifdef __CONFIG_SINGLE_CORE__
		warn("You currently can't have networking if you boot into single core mode!!\n");
	#else
		rl8168_init();		
		ne2k_init();
		e1000_init();
	#endif // __CONFIG_SINGLE_CORE__
	#endif // __CONFIG_NETWORKING__

	perfmon_init();
		
#ifdef __CONFIG_MONITOR_ON_INT__
	/* Handler to read a char from the interrupt source and call the monitor.
	 * Need to read the character so the device will send another interrupt.
	 * Note this will read from both the serial and the keyboard, and throw away
	 * the result.  We condition, since we don't want to trigger on a keyboard
	 * up interrupt */
	void mon_int(struct trapframe *tf, void *data)
	{
		// Enable interrupts here so that we can receive 
		// other interrupts (e.g. from the NIC)
		enable_irq();
		if (cons_getc())
			monitor(0);
	}
开发者ID:kstraube,项目名称:hysim,代码行数:54,代码来源:init.c


示例14: sys_cgetc

// Read a character from the system console.
// Returns the character.
static int
sys_cgetc(void)
{
    int c;

    // The cons_getc() primitive doesn't wait for a character,
    // but the sys_cgetc() system call does.
    while ((c = cons_getc()) == 0)
        /* do nothing */;

    return c;
}
开发者ID:BGCX262,项目名称:zt-jos-svn-to-git,代码行数:14,代码来源:syscall.c


示例15: sys_cgetc

// Read a character from the system console.
// Returns the character.
static int
sys_cgetc(void)
{
	int c;

	/* The cons_getc() primitive doesn't wait for a character, But we do.
	 * TODO: Make kernel interruptable later
	 * Now just a makeshift, without kernel being interruptable, Ether
	 * device refuses to function properly.
	 */
	while ((c = cons_getc()) == 0);
/*  { */
/* 		assert(curenv->env_status == ENV_RUNNING); */
/* 		spin_lock(&curenv->env_lock); */
/* 		curenv->env_status = ENV_RUNNABLE; */
/* 		spin_unlock(&curenv->env_lock); */
/* 		sched_yield();/\* This enables daemons to get CPU cycles when */
/* 			       * sh is running. */
/* 			       *\/ */
/* 	} */
	return c;
}
开发者ID:liuyuan,项目名称:kludgeos,代码行数:24,代码来源:syscall.c


示例16: sys_cgetc

// Read a character from the system console without blocking.
// Returns the character, or 0 if there is no input waiting.
static int
sys_cgetc(void)
{
	return cons_getc();
}
开发者ID:Insecurity-plan15,项目名称:JOS-Microkernel,代码行数:7,代码来源:syscall.c


示例17: trap_dispatch

static void
trap_dispatch(struct trapframe *tf) {
    char c;

    int ret=0;

    switch (tf->tf_trapno) {
    case T_PGFLT:  //page fault
        if ((ret = pgfault_handler(tf)) != 0) {
            print_trapframe(tf);
            if (current == NULL) {
                panic("handle pgfault failed. ret=%d\n", ret);
            }
            else {
                if (trap_in_kernel(tf)) {
                    panic("handle pgfault failed in kernel mode. ret=%d\n", ret);
                }
                cprintf("killed by kernel.\n");
                panic("handle user mode pgfault failed. ret=%d\n", ret); 
                do_exit(-E_KILLED);
            }
        }
        break;
    case T_SYSCALL:
        syscall();
        break;
    case IRQ_OFFSET + IRQ_TIMER:
#if 0
    LAB3 : If some page replacement algorithm(such as CLOCK PRA) need tick to change the priority of pages,
    then you can add code here. 
#endif
        /* LAB1 2011010312 : STEP 3 */
        /* handle the timer interrupt */
        /* (1) After a timer interrupt, you should record this event using a global variable (increase it), such as ticks in kern/driver/clock.c
         * (2) Every TICK_NUM cycle, you can print some info using a funciton, such as print_ticks().
         * (3) Too Simple? Yes, I think so!
         */
        /* LAB5 2011010312 */
        /* you should upate you lab1 code (just add ONE or TWO lines of code):
         *    Every TICK_NUM cycle, you should set current process's current->need_resched = 1
         */
        ticks++;
        if(ticks == TICK_NUM) {
            ticks = 0;
            current->need_resched = 1;
        }
        break;
    case IRQ_OFFSET + IRQ_COM1:
        c = cons_getc();
        cprintf("serial [%03d] %c\n", c, c);
        break;
    case IRQ_OFFSET + IRQ_KBD:
        c = cons_getc();
        cprintf("kbd [%03d] %c\n", c, c);
        break;
    //LAB1 CHALLENGE 1 : YOUR CODE you should modify below codes.
    case T_SWITCH_TOU:
    case T_SWITCH_TOK:
        panic("T_SWITCH_** ??\n");
        break;
    case IRQ_OFFSET + IRQ_IDE1:
    case IRQ_OFFSET + IRQ_IDE2:
        /* do nothing */
        break;
    default:
        print_trapframe(tf);
        if (current != NULL) {
            cprintf("unhandled trap.\n");
            do_exit(-E_KILLED);
        }
        // in kernel, it must be a mistake
        panic("unexpected trap in kernel.\n");

    }
}
开发者ID:thuyangyu,项目名称:ucore_lab,代码行数:75,代码来源:trap.c


示例18: trap_dispatch

static void
trap_dispatch(struct trapframe *tf) {
    char c;

    int ret=0;

    switch (tf->tf_trapno) {
    case T_PGFLT:  //page fault
        if ((ret = pgfault_handler(tf)) != 0) {
            print_trapframe(tf);
            if (current == NULL) {
                panic("handle pgfault failed. ret=%d\n", ret);
            }
            else {
                if (trap_in_kernel(tf)) {
                    panic("handle pgfault failed in kernel mode. ret=%d\n", ret);
                }
                cprintf("killed by kernel.\n");
                panic("handle user mode pgfault failed. ret=%d\n", ret); 
                do_exit(-E_KILLED);
            }
        }
        break;
    case T_SYSCALL:
        syscall();
        break;
    case IRQ_OFFSET + IRQ_TIMER:
#if 0
    LAB3 : If some page replacement algorithm(such as CLOCK PRA) need tick to change the priority of pages,
    then you can add code here. 
#endif
        /* LAB1 YOUR CODE : STEP 3 */
        /* handle the timer interrupt */
        /* (1) After a timer interrupt, you should record this event using a global variable (increase it), such as ticks in kern/driver/clock.c
         * (2) Every TICK_NUM cycle, you can print some info using a funciton, such as print_ticks().
         * (3) Too Simple? Yes, I think so!
         */
        /* LAB5 YOUR CODE */
        /* you should upate you lab1 code (just add ONE or TWO lines of code):
         *    Every TICK_NUM cycle, you should set current process's current->need_resched = 1
         */
        /* LAB6 YOUR CODE */
        /* IMPORTANT FUNCTIONS:
	     * run_timer_list
	     *----------------------
	     * you should update your lab5 code (just add ONE or TWO lines of code):
         *    Every tick, you should update the system time, iterate the timers, and trigger the timers which are end to call scheduler.
         *    You can use one funcitons to finish all these things.
         */
		ticks ++;
		run_timer_list();

        break;
    case IRQ_OFFSET + IRQ_COM1:
        c = cons_getc();
        cprintf("serial [%03d] %c\n", c, c);
        break;
    case IRQ_OFFSET + IRQ_KBD:
        c = cons_getc();
        cprintf("kbd [%03d] %c\n", c, c);
        break;
    //LAB1 CHALLENGE 1 : 13307130148 you should modify below codes.
    case T_SWITCH_TOU:
		cprintf("To user mode\n");
		if (tf->tf_cs != USER_CS) {
			tfk2u = *tf;
			tfk2u.tf_cs = USER_CS;
			tfk2u.tf_ds = tfk2u.tf_es = tfk2u.tf_ss = USER_DS;
			tfk2u.tf_esp = (uint32_t)tf + sizeof(struct trapframe) - 8;
			tfk2u.tf_eflags |= (3 << 12);
			*((uint32_t *)tf - 1) = (uint32_t)&tfk2u;
		}
		break;
    case T_SWITCH_TOK:
		cprintf("To kernel mode\n");
        //panic("T_SWITCH_** ??\n");
		struct trapframe *tfu2k;
		if (tf->tf_cs != KERNEL_CS) {
			tf->tf_cs = KERNEL_CS;
			tf->tf_ds = tf->tf_es = KERNEL_DS;
			tf->tf_eflags &= ~(3 << 12);
			tfu2k = (struct trapframe*)((uint32_t)tf->tf_esp - sizeof(struct trapframe) + 8);
			memmove(tfu2k, tf, sizeof(struct trapframe)-8);
			*((uint32_t *)tf - 1) = (uint32_t)tfu2k;
		}
        break;
    case IRQ_OFFSET + IRQ_IDE1:
    case IRQ_OFFSET + IRQ_IDE2:
        /* do nothing */
        break;
    default:
        print_trapframe(tf);
        if (current != NULL) {
            cprintf("unhandled trap.\n");
            do_exit(-E_KILLED);
        }
        // in kernel, it must be a mistake
        panic("unexpected trap in kernel.\n");

    }
//.........这里部分代码省略.........
开发者ID:czy941030,项目名称:ucore_lab,代码行数:101,代码来源:trap.c


示例19: trap_dispatch

static void
trap_dispatch(struct trapframe *tf) {
    char c;

    int ret=0;

    switch (tf->tf_trapno) {
    case T_PGFLT:  //page fault
        if ((ret = pgfault_handler(tf)) != 0) {
            print_trapframe(tf);
            if (current == NULL) {
                panic("handle pgfault failed. ret=%d\n", ret);
            }
            else {
                if (trap_in_kernel(tf)) {
                    panic("handle pgfault failed in kernel mode. ret=%d\n", ret);
                }
                cprintf("killed by kernel.\n");
                panic("handle user mode pgfault failed. ret=%d\n", ret); 
                do_exit(-E_KILLED);
            }
        }
        break;
    case T_SYSCALL:
        syscall();
        break;
    case IRQ_OFFSET + IRQ_TIMER:
#if 0
    LAB3 : If some page replacement algorithm(such as CLOCK PRA) need tick to change the priority of pages,
    then you can add code here. 
#endif
        /* LAB1 2013011365 : STEP 3 */
        /* handle the timer interrupt */
        /* (1) After a timer interrupt, you should record this event using a global variable (increase it), such as ticks in kern/driver/clock.c
         * (2) Every TICK_NUM cycle, you can print some info using a funciton, such as print_ticks().
         * (3) Too Simple? Yes, I think so!
         */
        /* LAB5 YOUR CODE */
        /* you should upate you lab1 code (just add ONE or TWO lines of code):
         *    Every TICK_NUM cycle, you should set current process's current->need_resched = 1
         */
        if(++ticks % TICK_NUM == 0) {
			//print_ticks();
			current->need_resched = 1;
		}
        break;
    case IRQ_OFFSET + IRQ_COM1:
        c = cons_getc();
        cprintf("serial [%03d] %c\n", c, c);
        break;
    case IRQ_OFFSET + IRQ_KBD:
        c = cons_getc();
        cprintf("kbd [%03d] %c\n", c, c);
        break;
    //LAB1 CHALLENGE 1 : YOUR CODE you should modify below codes.
    case T_SWITCH_TOU:
    	if(tf->tf_cs != USER_CS) {
			user_stack = *tf;
			user_stack.tf_cs = USER_CS;
			user_stack.tf_ds = USER_DS;
			user_stack.tf_ss = USER_DS;
			user_stack.tf_es = USER_DS;
			user_stack.tf_esp = (uint32_t)tf + sizeof(struct trapframe) - 8;
			user_stack.tf_eflags |= FL_IOPL_MASK;
			*((uint32_t *)tf - 1) = (uint32_t)&user_stack;
		}
		break;
    case T_SWITCH_TOK:
        if(tf->tf_cs != KERNEL_CS) {
			tf->tf_cs = KERNEL_CS;
			tf->tf_ds = KERNEL_DS;
			tf->tf_es = KERNEL_DS;
			tf->tf_eflags &= ~FL_IOPL_MASK;
			struct trapframe* k = (struct trapframe*)(tf->tf_esp - (sizeof(struct trapframe) - 8));
			memmove(k, tf, sizeof(struct trapframe) -8);
			*((uint32_t *)tf - 1) = (uint32_t)k;

		}
		break;
    case IRQ_OFFSET + IRQ_IDE1:
    case IRQ_OFFSET + IRQ_IDE2:
        /* do nothing */
        break;
    default:
        print_trapframe(tf);
        if (current != NULL) {
            cprintf("unhandled trap.\n");
            do_exit(-E_KILLED);
        }
        // in kernel, it must be a mistake
        panic("unexpected trap in kernel.\n");

    }
}
开发者ID:maye9999,项目名称:ucore_os_lab,代码行数:94,代码来源:trap.c


示例20: trap_dispatch

static void
trap_dispatch(struct trapframe *tf) {
    char c;

    int ret;

    switch (tf->tf_trapno) {
    case T_PGFLT:  //page fault
        if ((ret = pgfault_handler(tf)) != 0) {
            print_trapframe(tf);
            panic("handle pgfault failed. %e\n", ret);
        }
        break;
    case IRQ_OFFSET + IRQ_TIMER:
#if 0
    LAB3 : If some page replacement algorithm(such as CLOCK PRA) need tick to change the priority of pages, 
    then you can add code here. 
#endif
        /* LAB1 YOUR CODE : STEP 3 */
        /* handle the timer interrupt */
        /* (1) After a timer interrupt, you should record this event using a global variable (increase it), such as ticks in kern/driver/clock.c
         * (2) Every TICK_NUM cycle, you can print some info using a funciton, such as print_ticks().
         * (3) Too Simple? Yes, I think so!
         */
        ticks ++;
        if (ticks % TICK_NUM == 0)
       		print_ticks();
        break;
    case IRQ_OFFSET + IRQ_COM1:
        c = cons_getc();
        cprintf("serial [%03d] %c\n", c, c);
        break;
    case IRQ_OFFSET + IRQ_KBD:
        c = cons_getc();
        cprintf("kbd [%03d] %c\n", c, c);
        if (c == '0')
        {
        	user2kernel(tf);
        }
        if (c == '3')
        {
			kernel2user(tf);
        }
        print_trapframe(tf);
        break;
    //LAB1 CHALLENGE 1 : YOUR CODE you should modify below codes.
    case T_SWITCH_TOU:
    	kernel2user(tf);
/*    	if (tf->tf_cs != USER_CS)
    	{
    		switchk2u = *tf;
    		switchk2u.tf_cs = USER_CS;
    		switchk2u.tf_ds = switchk2u.tf_es = switchk2u.tf_ss = USER_DS;
    		switchk2u.tf_esp = (uint32_t)tf + sizeof(struct trapframe)-8;

    		switchk2u.tf_eflags |= FL_IOPL_MASK;

    		*((uint32_t *)tf -1) = (uint32_t)&switchk2u;
    	}*/
    	break;
    case T_SWITCH_TOK:
        //panic("T_SWITCH_** ??\n");
        user2kernel(tf);
/*        if (tf->tf_cs != KERNEL_CS)
		{
			tf->tf_cs = KERNEL_CS;
			tf->tf_ds = tf->tf_es = KERNEL_DS;
			tf->tf_eflags &= ~FL_IOPL_MASK;
			switchu2k = (struct trapframe *)(tf->tf_esp - (sizeof(struct trapframe)-8));
			memmove(switchu2k, tf, sizeof(struct trapframe)-8);
			*((uint32_t*)tf-1) = (uint32_t)switchu2k;
		}*/
        break;
    case IRQ_OFFSET + IRQ_IDE1:
    case IRQ_OFFSET + IRQ_IDE2:
        /* do nothing */
        break;
    default:
        // in kernel, it must be a mistake
        if ((tf->tf_cs & 3) == 0) {
            print_trapframe(tf);
            panic("unexpected trap in kernel.\n");
        }
    }
}
开发者ID:sjyfok,项目名称:moocos,代码行数:85,代码来源:trap.c



注:本文中的cons_getc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ cons_init函数代码示例发布时间:2022-05-30
下一篇:
C++ cons函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap