Ejemplo n.º 1
0
static void
trap_dispatch(struct Trapframe *tf)
{
	// Handle processor exceptions.
	// LAB 3: Your code here.
//	if (tf->tf_trapno == 14) 
//		page_fault_handler(tf);
	cprintf("TRAP NO : %d\n", tf->tf_trapno);
	int r;
	switch (tf->tf_trapno) {
		case T_PGFLT : 
			page_fault_handler(tf);
			break;
		case T_BRKPT : 
			monitor(tf);
			break;
		case T_DEBUG : 
			monitor(tf);
			break;
		case T_SYSCALL :
			r = syscall(tf->tf_regs.reg_eax, tf->tf_regs.reg_edx, tf->tf_regs.reg_ecx, tf->tf_regs.reg_ebx, tf->tf_regs.reg_edi, tf->tf_regs.reg_esi);
			tf->tf_regs.reg_eax = r;
			break;
		default :	
		// Unexpected trap: The user process or the kernel has a bug.
		print_trapframe(tf);
		if (tf->tf_cs == GD_KT)
			panic("unhandled trap in kernel");
		else {
			env_destroy(curenv);
			return;
		}
	}
}
Ejemplo n.º 2
0
Archivo: trap.c Proyecto: chenkexin/jos
static void
trap_dispatch(struct Trapframe *tf)
{
	// Handle processor exceptions.
	// LAB 3: Your code here.
	uint32_t fault_va;
	if(tf->tf_trapno >= 0 && tf->tf_trapno < 255)
	{
		switch(tf->tf_trapno)
		{
			case T_PGFLT://page fault
				page_fault_handler(tf);
				return;
			case T_BRKPT:
				monitor(tf);
				return;
			case T_SYSCALL:
	
			//fault_va = rcr2();
			//cprintf("[%08x] user fault va %08x ip %08x\n",curenv->env_id, fault_va, tf->tf_eip);
			
			//cprintf("T_SYSCALL\n");
//				print_trapframe(tf);
				tf->tf_regs.reg_eax = syscall(tf->tf_regs.reg_eax, tf->tf_regs.reg_edx, tf->tf_regs.reg_ecx,tf->tf_regs.reg_ebx, tf->tf_regs.reg_edi, tf->tf_regs.reg_esi);
				
				return;
		}
	}

	// Handle spurious interrupts
	// The hardware sometimes raises these because of noise on the
	// IRQ line or other reasons. We don't care.
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_SPURIOUS) {
		cprintf("Spurious interrupt on irq 7\n");
		print_trapframe(tf);
		return;
	}

	// Handle clock interrupts. Don't forget to acknowledge the
	// interrupt using lapic_eoi() before calling the scheduler!
	// LAB 4: Your code here.
    if (tf->tf_trapno == IRQ_OFFSET + IRQ_TIMER) {
        lapic_eoi();
        sched_yield();
        return;
    }

	// Handle keyboard and serial interrupts.
	// LAB 5: Your code here.

	// Unexpected trap: The user process or the kernel has a bug.
	print_trapframe(tf);

	if (tf->tf_cs == GD_KT)
		panic("unhandled trap in kernel");
	else {
		env_destroy(curenv);
		return;
	}
}
Ejemplo n.º 3
0
static void
trap_dispatch(struct Trapframe *tf)
{
	// Handle processor exceptions.
	// LAB 3: Your code here.
	switch(tf->tf_trapno)
	{
		case T_PGFLT:	page_fault_handler(tf);
				return;
		case T_BRKPT:	monitor(tf);
				return;
		case T_SYSCALL:	
				tf->tf_regs.reg_rax = syscall(tf->tf_regs.reg_rax,tf->tf_regs.reg_rdx,tf->tf_regs.reg_rcx,tf->tf_regs.reg_rbx, tf->tf_regs.reg_rdi, tf->tf_regs.reg_rsi);
				return;
	}
	// Unexpected trap: The user process or the kernel has a bug.

	print_trapframe(tf);
	if (tf->tf_cs == GD_KT)
		panic("unhandled trap in kernel");
	else {
		env_destroy(curenv);
		return;
	}
}
Ejemplo n.º 4
0
static void
trap_dispatch(struct Trapframe *tf)
{
	// Handle processor exceptions.
	// LAB 3: Your code here.
	// Handle clock and serial interrupts.
	// LAB 4: Your code here.
	switch(tf->tf_trapno){
			case T_SYSCALL:
				tf->tf_regs.reg_eax = syscall(tf->tf_regs.reg_eax,
					                          tf->tf_regs.reg_edx,
					                          tf->tf_regs.reg_ecx,
					                          tf->tf_regs.reg_ebx,
					                          tf->tf_regs.reg_edi,
					                          tf->tf_regs.reg_esi);
				return ;
			case T_PGFLT:
				page_fault_handler(tf);
				return ;
			case T_BRKPT:
				monitor(tf);
				return ;
			case IRQ_OFFSET + IRQ_TIMER:
				sched_yield();
				return ;
    }
	// Unexpected trap: The user process or the kernel has a bug.
	print_trapframe(tf);
	if (tf->tf_cs == GD_KT)
		panic("unhandled trap in kernel");
	else {
		env_destroy(curenv);
		return;
	}
}
Ejemplo n.º 5
0
void segv_sigaction(int signum, siginfo_t* sinfo, void * p){
  // Check signal
  if (SIGSEGV != signum) {
    printf ("Bad handler for bad signal...\n");
    exit (1);
  }


  // Check if fault is from managed segment
  if(sinfo->si_addr < start_addr || sinfo->si_addr >= size*PAGESIZE+start_addr){
    printf("Segfault somewhere else... good luck...\n");
    printf(" Hint: run the debugger and set a breakpoint for this line\n");
    exit(1);
  }

  // Check cause of fault
  if(sinfo->si_code != SEGV_ACCERR){
    printf("Object not mapped...\n");
    printf(" Hint: run the debugger and set a breakpoint for this line\n");
    exit(1);
  }

  // Find out virtual page in fault
  page_virt pv=PAGEOF(sinfo->si_addr);

  // If not invalid then setDirtyBit
  // Allow read, but wait until page has been loaded...
  if(mmu_array[pv].pp != INVALID){
    if(!mmu_array[pv].accessed){
      struct timeval delay;
      struct timeval now;
      gettimeofday(&now,NULL);
      timeradd(&delay,&delay_load,&delay);
      timersub(&delay,&now,&delay);
      if(delay.tv_sec >= 0){
    	  int UNUSED r;
    	  struct timespec s;
    	  TV2TS(delay,s);
    	  //do{
    	  //	  r=nanosleep(&s,&s);
    	  //  }while(r < 0 && errno == EINTR);
      }
      mmu_setAccessedBit(pv);
    }else{
      mmu_setDirtyBit(pv);
    }
  }else{
  // Else call page fault handler
	  stats_faults++;
    page_fault_handler(pv);
  }

  // Check that translation has been added
  if(mmu_array[pv].pp == INVALID){
    printf("Page fault handler did not update MMU...\n");
    exit(1);
  }
}
Ejemplo n.º 6
0
static void
trap_dispatch(struct Trapframe *tf)
{
	// Handle processor exceptions.
	// LAB 3: Your code here.

	// Handle spurious interrupts
	// The hardware sometimes raises these because of noise on the
	// IRQ line or other reasons. We don't care.
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_SPURIOUS) {
		cprintf("Spurious interrupt on irq 7\n");
		print_trapframe(tf);
		return;
	}

	// Handle clock interrupts. Don't forget to acknowledge the
	// interrupt using lapic_eoi() before calling the scheduler!
	// LAB 4: Your code here.

	if (tf ->tf_trapno == IRQ_OFFSET + IRQ_TIMER) {
		lapic_eoi();
		sched_yield();
		return;
	}

	// Unexpected trap: The user process or the kernel has a bug.
//	if (tf->tf_trapno == 14) 
//		page_fault_handler(tf);
//	cprintf("TRAP NO : %d\n", tf->tf_trapno);
	int r;
	switch (tf->tf_trapno) {
		case T_PGFLT : 
			page_fault_handler(tf);
			break;
		case T_BRKPT : 
			monitor(tf);
			break;
		case T_DEBUG : 
			monitor(tf);
			break;
		case T_SYSCALL :
			r = syscall(tf->tf_regs.reg_eax, tf->tf_regs.reg_edx, tf->tf_regs.reg_ecx, tf->tf_regs.reg_ebx, tf->tf_regs.reg_edi, tf->tf_regs.reg_esi);
			tf->tf_regs.reg_eax = r;
			break;
		default :	
		// Unexpected trap: The user process or the kernel has a bug.
		print_trapframe(tf);
		if (tf->tf_cs == GD_KT)
			panic("unhandled trap in kernel");
		else {
			env_destroy(curenv);
			return;
		}
	}
}
Ejemplo n.º 7
0
void
trap(struct Trapframe *tf)
{
    int ret;

	// Handle processor exceptions
	// Your code here.
    switch(tf->tf_trapno)
    {
        case T_BRKPT:
            while(1)
                monitor(NULL);
            break;
        case T_PGFLT:
            page_fault_handler(tf);
            tf->tf_eflags |= FL_IF;
            //env_pop_tf(tf);
            memcpy(&curenv->env_tf, tf, sizeof(*tf));
            env_run(curenv);
            return;
        case T_SYSCALL:
            ret = syscall(tf->tf_eax, tf->tf_edx, tf->tf_ecx, tf->tf_ebx,
                    tf->tf_edi, tf->tf_esi);
            tf->tf_eax = ret;
            tf->tf_eflags |= FL_IF;
            // env_pop_tf(tf);
            memcpy(&curenv->env_tf, tf, sizeof(*tf));
            env_run(curenv);
        case IRQ_OFFSET:
            sched_yield();
            break;
        case IRQ_KBD:
            kbd_intr();
            memcpy(&curenv->env_tf, tf, sizeof(*tf));
            env_run(curenv);
            break;
        default:
            break;
    }

	// the user process or the kernel has a bug.
	print_trapframe(tf);
	if (tf->tf_cs == GD_KT)
		panic("unhandled trap in kernel");
	else {
		env_destroy(curenv);
		return;
	}
}
Ejemplo n.º 8
0
static void
trap_dispatch(struct Trapframe *tf)
{
	// Handle processor exceptions.
	// LAB 3: Your code here.
	uint32_t ret;

	if ( tf->tf_trapno == T_PGFLT ) {
		page_fault_handler(tf);
		return;
	}
	if ( tf->tf_trapno == T_BRKPT ) {
		monitor(tf);
		return;
	}
	if ( tf->tf_trapno == T_SYSCALL ) {
		//cprintf("==== i am here\n");
		ret = syscall( tf->tf_regs.reg_eax, tf->tf_regs.reg_edx, tf->tf_regs.reg_ecx, tf->tf_regs.reg_ebx, tf->tf_regs.reg_edi, tf->tf_regs.reg_esi);
		if ( ret < 0 ) {
			panic("trap_dispatch: The System Call number is invalid");
		}
		tf->tf_regs.reg_eax = ret;
		//cprintf("bobo -------------:%x\n", tf->tf_regs.reg_eax);
		return;
	}

	// Handle spurious interrupts
	// The hardware sometimes raises these because of noise on the
	// IRQ line or other reasons. We don't care.
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_SPURIOUS) {
		cprintf("Spurious interrupt on irq 7\n");
		print_trapframe(tf);
		return;
	}

	// Handle clock interrupts. Don't forget to acknowledge the
	// interrupt using lapic_eoi() before calling the scheduler!
	// LAB 4: Your code here.

	// Unexpected trap: The user process or the kernel has a bug.
	print_trapframe(tf);
	if (tf->tf_cs == GD_KT)
		panic("unhandled trap in kernel");
	else {
		env_destroy(curenv);
		return;
	}
}
Ejemplo n.º 9
0
Archivo: trap.c Proyecto: jjli418/jos
void
trap(struct Trapframe *tf)
{
	// print_trapframe(tf);

	// Handle processor exceptions
	// Your code here.

	if(tf->tf_trapno == 0xE)
		page_fault_handler(tf);
	else if(tf->tf_trapno == T_SYSCALL)
	{
		syscall(tf->tf_eax, tf->tf_edx, tf->tf_ecx, tf->tf_ebx, tf->tf_esi, tf->tf_edi);
	}
	// Handle external interrupts
	if (tf->tf_trapno == IRQ_OFFSET+0) {
		// irq 0 -- clock interrupt
		sched_yield();
	}
	if (tf->tf_trapno == IRQ_OFFSET+4) {
		serial_intr();
		return;
	}
	if (IRQ_OFFSET <= tf->tf_trapno 
			&& tf->tf_trapno < IRQ_OFFSET+MAX_IRQS) {
		// just ingore spurious interrupts
		printf("spurious interrupt on irq %d\n",
			tf->tf_trapno - IRQ_OFFSET);
		print_trapframe(tf);
		return;
	}

	// the user process or the kernel has a bug.
	print_trapframe(tf);
	if (tf->tf_cs == GD_KT)
		panic("unhandled trap in kernel");
	else {
		env_destroy(curenv);
		return;
	}
}
Ejemplo n.º 10
0
static void
trap_dispatch(struct Trapframe *tf)
{
	int32_t ret_code;
	// Handle processor exceptions.
	// LAB 3: Your code here.
	switch(tf->tf_trapno) {
		case (T_PGFLT):
			page_fault_handler(tf);
			break; 
		case (T_BRKPT):
			print_trapframe(tf);
			monitor(tf);		
			break;
		case (T_DEBUG):
			monitor(tf);
			break;
		case (T_SYSCALL):
	//		print_trapframe(tf);
			ret_code = syscall(
					tf->tf_regs.reg_eax,
					tf->tf_regs.reg_edx,
					tf->tf_regs.reg_ecx,
					tf->tf_regs.reg_ebx,
					tf->tf_regs.reg_edi,
					tf->tf_regs.reg_esi);
			tf->tf_regs.reg_eax = ret_code;
			break;
 		default:
			// Unexpected trap: The user process or the kernel has a bug.
			print_trapframe(tf);
			if (tf->tf_cs == GD_KT)
				panic("unhandled trap in kernel");
			else {
				env_destroy(curenv);
				return;
			}
	}
}
Ejemplo n.º 11
0
/**
  * @author Ivan Gualandri
  * @version 1.0
  *
  * Questa funzione gestira a livello centralizzato le varie eccezione
  */
void _globalException(int n, int error)
{
  switch (n) {

    case DIVIDE_ERROR:
    _kputs("Divide Error\n");
    break;

    case DEBUG_EXC:
    _kputs("Debug Exception\n");
    break;

    case NMI_INTERRUPT:
    _kputs("NMI Exception\n");
    break;

    case OVERFLOW:
    _kputs("OverFlow Exception\n");
    break;
	 
    case BOUND_RANGE_EXCEED:
    _kputs("Bound Exception\n");
    break;

    case DEV_NOT_AVL:
    _kputs("Device Not Available Exception\n");
    break;

    case COPROC_SEG_OVERRUN:
    _kputs("CoProcessor Segment Overrun\n");
    break;

    case BREAKPOINT:
    _kputs("BreakPoint\n");
    break;

    case INVALID_TSS:
    _kputs("Invalid TSS\n");
    break;

    case SEGMENT_NOT_PRESENT:
    _kputs("Segment Not Present\n");
    break;

    case STACK_SEGMENT_FAULT:
    _kputs("Stack Segment Fault Exception\n");
    break;

    case GENERAL_PROTECTION:
    _kputs("General Protection Exception\n");
    break;

    case INVALID_OPCODE:
    _kputs("Invalid Opcode Exception\n");
    break;

    case PAGE_FAULT:
    page_fault_handler (error);
    break;

    case INT_RSV:
    _kputs("Intel Reserved\n");
    break;

    case FLOATING_POINT_ERR:
    _kputs("Floating Point Exception\n");
    break;

    case ALIGNMENT_CHECK:
    _kputs("Alignment Check Exception\n");
    break;

    case MACHINE_CHECK:
    _kputs("Machine Check Exception\n");
    break;

    case DOUBLE_FAULT:
    _kputs("Double Fault Exception\n");
    break;

    case SIMD_FP_EXC:
    _kputs ("Simd Floating Point Exception\n");
    break;

    default:
    _kputs ("Unknown exception\n");
    break;

  }
}
Ejemplo n.º 12
0
static void
trap_dispatch(struct Trapframe *tf)
{
	static int page_to_age = 0;
	int page_to_age_first = page_to_age;
	int num_page_updates = NPAGEUPDATES_FACTOR*NPAGESFREE_LOW_THRESHOLD;
	struct PteChain *pp_refs_chain;
	char page_accessed;

	// Handle processor exceptions.
	// LAB 3: Your code here.
	if (tf->tf_trapno == T_PGFLT) {
		page_fault_handler(tf);
		return;
	}
	else if (tf->tf_trapno == T_BRKPT) {
		monitor(tf);    // breakpoint exceptions invoke the kernel monitor
		return;
	}
	else if (tf->tf_trapno == T_SYSCALL) {
		tf->tf_regs.reg_eax = syscall(tf->tf_regs.reg_eax, tf->tf_regs.reg_edx, tf->tf_regs.reg_ecx, tf->tf_regs.reg_ebx, tf->tf_regs.reg_edi, tf->tf_regs.reg_esi);
		return;
	}

	// Handle spurious interrupts
	// The hardware sometimes raises these because of noise on the
	// IRQ line or other reasons. We don't care.
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_SPURIOUS) {
		cprintf("Spurious interrupt on irq 7\n");
		print_trapframe(tf);
		return;
	}

	// Handle clock interrupts. Don't forget to acknowledge the
	// interrupt using lapic_eoi() before calling the scheduler!
	// LAB 4: Your code here.
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_TIMER) {
		lapic_eoi();

		// Update the age of some physical pages

		// If we fall below the thresholds, update more pages than usual
		// This is somewhat arbitrary, we can tweak these numbers
		// We also might want to increase the order of magnitude of the number of pages we update per clock tick
		// This will require some testing and profiling
		// There is also no reason why num_page_updates is based on the threshold values, it can be incremented by its own macros
		if (num_free_pages <= NPAGESFREE_LOW_THRESHOLD) {
			num_page_updates += NPAGEUPDATES_FACTOR*NPAGESFREE_HIGH_THRESHOLD;
		}
		if (num_free_pages <= NPAGESFREE_HIGH_THRESHOLD) {
			num_page_updates += NPAGEUPDATES_FACTOR*NPAGESFREE_LOW_THRESHOLD;
		}

		for ( ; num_page_updates >= 0; --num_page_updates) {
			// Find the next page that is currently mapped in user space, by finding one with a nonzero pp_ref
			while (!pages[page_to_age].pp_ref) {
				// If we wrap around to where we started, stop updating page ages
				if ((page_to_age=(page_to_age+1)%npages) == page_to_age_first) {
					goto end_of_page_age_updates;
				}
			}

			// Iterate through all of the user space PTEs that map to this page
			// If any of them have been accessed, increment the age, and then clear the PTE_A bit in all of the PTEs
			page_accessed = 0;
			for (pp_refs_chain = pages[page_to_age].pp_refs_chain; pp_refs_chain; pp_refs_chain = pp_refs_chain->pc_link) {
				if (*pp_refs_chain->pc_pte & PTE_A) {
					page_accessed = 1;
					pages[page_to_age].age += PAGE_AGE_INCREMENT_ON_ACCESS;
					for ( ; pp_refs_chain; pp_refs_chain = pp_refs_chain->pc_link) {
						*(pp_refs_chain->pc_pte) &= ~PTE_A;
					}
					break;
				}
			}
			pages[page_to_age].age = (pages[page_to_age].age > MAX_PAGE_AGE ? MAX_PAGE_AGE : pages[page_to_age].age);
			if (!page_accessed) {
				if (pages[page_to_age].age >= (uint8_t)PAGE_AGE_DECREMENT_ON_CLOCK) {
					pages[page_to_age].age -= (uint8_t)PAGE_AGE_DECREMENT_ON_CLOCK;
				}
				else {
					pages[page_to_age].age = 0;
				}
			}

			// If we wrap around to where we started, stop updating page ages
			if ((page_to_age=(page_to_age+1)%npages) == page_to_age_first) {
				goto end_of_page_age_updates;
			}
		}
		end_of_page_age_updates:
		sched_yield();
	}

	// Handle keyboard and serial interrupts.
	// LAB 5: Your code here.
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_KBD) {
		lapic_eoi();
		kbd_intr();
		return;
	}
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_SERIAL) {
		lapic_eoi();
		serial_intr();
		return;
	}

	// Unexpected trap: The user process or the kernel has a bug.
	print_trapframe(tf);
	if (tf->tf_cs == GD_KT)
		panic("unhandled trap in kernel");
	else {
		env_destroy(curenv);
		return;
	}
}
Ejemplo n.º 13
0
static void
trap_dispatch(struct Trapframe *tf)
{
	// Handle processor exceptions.
	// LAB 3: Your code here.
	
	int32_t ret;

	switch (tf->tf_trapno){
		case T_PGFLT:{ //14
			page_fault_handler(tf);
			return;
		}
		case T_BRKPT:{ //3 
			breakpoint_handler(tf);
			return;
		}
		case T_DEBUG:{
			breakpoint_handler(tf);
			return;
		}
		case T_SYSCALL:{
			ret = system_call_handler(tf);
			tf->tf_regs.reg_eax = ret;
			return;
		}
		case IRQ_OFFSET+IRQ_TIMER:{
			lapic_eoi();
			time_tick();
			sched_yield();
			return;
		}
		case IRQ_OFFSET+IRQ_KBD:{
			kbd_intr();
			return;
		}
		case IRQ_OFFSET+IRQ_SERIAL:{
			serial_intr();
			return;
		}
		case IRQ_OFFSET+IRQ_E1000:{
			e1000_trap_handler();
			return;
		}
	}	

	// Handle spurious interrupts
	// The hardware sometimes raises these because of noise on the
	// IRQ line or other reasons. We don't care.
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_SPURIOUS) {
		cprintf("Spurious interrupt on irq 7\n");
		print_trapframe(tf);
		return;
	}

	// Handle clock interrupts. Don't forget to acknowledge the
	// interrupt using lapic_eoi() before calling the scheduler!
	// LAB 4: Your code here.

	// Add time tick increment to clock interrupts.
	// Be careful! In multiprocessors, clock interrupts are
	// triggered on every CPU.
	// LAB 6: Your code here.


	// Handle keyboard and serial interrupts.
	// LAB 5: Your code here.

	// Unexpected trap: The user process or the kernel has a bug.
	print_trapframe(tf);
	if (tf->tf_cs == GD_KT)
	  panic("unhandled trap in kernel");
	else {
		env_destroy(curenv);
		return;
	}
}
Ejemplo n.º 14
0
Archivo: trap.c Proyecto: cky9301/6.828
static void
trap_dispatch(struct Trapframe *tf)
{
	// Handle processor exceptions.
	// LAB 3: Your code here.
        // TODO: chky
        int r;
        switch (tf->tf_trapno) {
          case T_PGFLT:
              page_fault_handler(tf);
              break;
          case T_BRKPT:
              // TODO: lab3 ex6 challenge
              monitor(tf);
              break;
          case T_SYSCALL:
              r = syscall(tf->tf_regs.reg_eax,    // syscallno
                          tf->tf_regs.reg_edx,    // a1
                          tf->tf_regs.reg_ecx,    // a2
                          tf->tf_regs.reg_ebx,    // a3
                          tf->tf_regs.reg_edi,    // a4
                          tf->tf_regs.reg_esi     // a5
                          );
              tf->tf_regs.reg_eax = r;
              return;
          default:
              break;
        }

	// Handle spurious interrupts
	// The hardware sometimes raises these because of noise on the
	// IRQ line or other reasons. We don't care.
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_SPURIOUS) {
		cprintf("Spurious interrupt on irq 7\n");
		print_trapframe(tf);
		return;
	}

	// Handle clock interrupts. Don't forget to acknowledge the
	// interrupt using lapic_eoi() before calling the scheduler!
	// LAB 4: Your code here.
        // TODO: chky
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_TIMER) {
	        lapic_eoi();
                sched_yield();
                return;
	}
        // chky end

	// Handle keyboard and serial interrupts.
	// LAB 5: Your code here.
        // TODO: chky
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_KBD) {
                kbd_intr();
                return;
	}
	
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_SERIAL) {
                serial_intr();
                return;
	}
        // chky end

	// Unexpected trap: The user process or the kernel has a bug.
	print_trapframe(tf);
	if (tf->tf_cs == GD_KT)
		panic("unhandled trap in kernel");
	else {
		env_destroy(curenv);
		return;
	}
}
Ejemplo n.º 15
0
static void
trap_dispatch(struct Trapframe *tf)
{
	int32_t res;
	// Handle processor exceptions.
	// LAB 3: Your code here.

	// Handle spurious interrupts
	// The hardware sometimes raises these because of noise on the
	// IRQ line or other reasons. We don't care.
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_SPURIOUS) {
		cprintf("Spurious interrupt on irq 7\n");
		print_trapframe(tf);
		return;
	}

	// Handle clock interrupts. Don't forget to acknowledge the
	// interrupt using lapic_eoi() before calling the scheduler!
	// LAB 4: Your code here.

	// Add time tick increment to clock interrupts.
	// Be careful! In multiprocessors, clock interrupts are
	// triggered on every CPU.
	// LAB 6: Your code here.


	// Handle keyboard and serial interrupts.
	// LAB 5: Your code here.

	//if(tf->tf_trapno == 48 && tf->tf_regs.reg_eax==7)
	//{
		//cprintf("trap no = %d at cpu %d env %x\n",tf->tf_trapno,cpunum(),curenv->env_id);		
		//print_trapframe(tf);
	//}
	switch(tf->tf_trapno)
	{
		case IRQ_OFFSET + IRQ_TIMER:
			//cprintf("clock interrupt on irq 7 on cpu %d\n",cpunum());
			//print_trapframe(tf);
			//cprintf("  eip  0x%08x\n", tf->tf_eip);
			//cprintf("  esp  0x%08x\n", tf->tf_esp);
			 lapic_eoi();
			 time_tick();
			 sched_yield();			
			 break;
		case IRQ_OFFSET + IRQ_SERIAL:
			 serial_intr(); break;
		case IRQ_OFFSET + IRQ_KBD:
			 kbd_intr(); break;
		case T_DIVIDE: tf->tf_regs.reg_ecx = 1; break; 
		case T_PGFLT: page_fault_handler(tf); goto err;
		case T_SYSCALL:
			 res = syscall(tf->tf_regs.reg_eax,tf->tf_regs.reg_edx,tf->tf_regs.reg_ecx,tf->tf_regs.reg_ebx,tf->tf_regs.reg_edi,tf->tf_regs.reg_esi); 
			 tf->tf_regs.reg_eax = res; break;
		case T_BRKPT:print_trapframe(tf);monitor(NULL);break;
		default: goto err;
	}
	
	return;
err:
	// Unexpected trap: The user process or the kernel has a bug.
	print_trapframe(tf);
	if (tf->tf_cs == GD_KT)
		panic("unhandled trap in kernel");
	else {
		env_destroy(curenv);
		return;
	}
}
Ejemplo n.º 16
0
static void
trap_dispatch(struct Trapframe *tf)
{
	// Handle processor exceptions.
	// LAB 3: Your code here.
	int32_t ret;
	// if (tf->tf_trapno != 48) cprintf("****** No. %d\n", tf->tf_trapno);
	// Handle clock interrupts.
	// LAB 4: Your code here.
	if (tf->tf_trapno == IRQ_OFFSET + 0){
		// cprintf("Timer interrupt\n");
		time_tick();
		sched_yield();
		return ;
	}

	// Add time tick increment to clock interrupts.
	// LAB 6: Your code here.

	// Add time_tick above sched_yield

	// Handle spurious interrupts
	// The hardware sometimes raises these because of noise on the
	// IRQ line or other reasons. We don't care.
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_SPURIOUS) {
		cprintf("Spurious interrupt on irq 7\n");
		print_trapframe(tf);
		return;
	}

	// LAB 7: Keyboard interface

	if (tf->tf_trapno == IRQ_OFFSET + 1){
		kbd_intr();
		return ;
	}

	if (tf->tf_trapno == IRQ_OFFSET + 4){
		serial_intr();
		return ;
	}

	if (tf->tf_trapno == T_DIVIDE || tf->tf_trapno == T_ILLOP || tf->tf_trapno == T_GPFLT){
		// cprintf("*************");
		// return ;
	}


	if (tf->tf_trapno == T_DEBUG){
		// Debug info
		// cprintf("*** trap %08x %s ***\n", tf->tf_trapno, trapname(tf->tf_trapno));
		// Invoke monitor
		monitor(tf);
		return ;
	}

	if (tf->tf_trapno == T_BRKPT){
		// Debug info
		// cprintf("*** trap %08x %s ***\n", tf->tf_trapno, trapname(tf->tf_trapno));
		// Invoke monitor
		monitor(tf);
		return ;
	}

	if (tf->tf_trapno == T_PGFLT){
		page_fault_handler(tf);
	}

	if (tf->tf_trapno == T_SYSCALL){
		ret = syscall(tf->tf_regs.reg_eax, 
				      tf->tf_regs.reg_edx, 
					  tf->tf_regs.reg_ecx,
					  tf->tf_regs.reg_ebx,
					  tf->tf_regs.reg_edi,
					  tf->tf_regs.reg_esi);
		tf->tf_regs.reg_eax = ret;
		return ;
	}

	// Handle keyboard and serial interrupts.
	// LAB 7: Your code here.

	// Unexpected trap: The user process or the kernel has a bug.
	print_trapframe(tf);
	if (tf->tf_cs == GD_KT){
		if (tf->tf_trapno == T_DEBUG){
			return ;
		}
		panic("unhandled trap in kernel");
	}
	else {
		env_destroy(curenv);
		return;
	}
}
Ejemplo n.º 17
0
static void
trap_dispatch(struct Trapframe *tf)
{

	// Handle processor exceptions.
	// LAB 3: Your code here.
//----------------------------------------  Lab3  ------------------------------------------------------------
    if (tf->tf_trapno == T_PGFLT) {
        //cprintf("pagefault!\n");
        page_fault_handler(tf);
        return;
    }
    if (tf->tf_trapno == T_BRKPT) {
        //cprintf("brkpt!\n");
        monitor(tf);
        return;
    }
    if (tf->tf_trapno == T_DEBUG) {
        my_monitor(tf);
        return;
    }
    if (tf->tf_trapno == T_SYSCALL) {
        //cprintf("Syscall!\n");
        tf->tf_regs.reg_eax = syscall(tf->tf_regs.reg_eax, tf->tf_regs.reg_edx, tf->tf_regs.reg_ecx, 
                              tf->tf_regs.reg_ebx, tf->tf_regs.reg_edi, tf->tf_regs.reg_esi);
        if (tf->tf_regs.reg_eax < 0)
            panic("syscall failed: %e\n", tf->tf_regs.reg_eax);
        return;
    }
//----------------------------------------  Lab3  ------------------------------------------------------------

	// Handle spurious interrupts
	// The hardware sometimes raises these because of noise on the
	// IRQ line or other reasons. We don't care.
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_SPURIOUS) {
		cprintf("Spurious interrupt on irq 7\n");
		print_trapframe(tf);
		return;
	}

	// Handle clock interrupts. Don't forget to acknowledge the
	// interrupt using lapic_eoi() before calling the scheduler!
	// LAB 4: Your code here.
//------------  Lab4  ----------------------------------------------------------------------------------------      
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_TIMER) {
		//	cprintf("clock interrupt!\n");
		lapic_eoi();
		sched_yield();
		return;
	}
//------------  Lab4  ----------------------------------------------------------------------------------------      

	// Unexpected trap: The user process or the kernel has a bug.
	print_trapframe(tf);
	if (tf->tf_cs == GD_KT)
		panic("unhandled trap in kernel");
	else {
		env_destroy(curenv);
		return;
	}
}
Ejemplo n.º 18
0
        static void
trap_dispatch(struct Trapframe *tf)
{
        // Handle processor exceptions.
        // LAB 3: Your code here.
        // dec 15,2010 sunus
        switch(tf->tf_trapno)
        {
                case T_PGFLT : 
                        {
                                page_fault_handler(tf);
                                break;
                        }
                case T_DEBUG :
                        cprintf("encounter a breakpoint!\n"); /*fall through*/
                case T_BRKPT :
                        {
                                monitor(tf);
                                break;
                        }
                case T_SYSCALL :
                        {
                                (tf->tf_regs).reg_eax = 
                                        syscall(
                                                        (tf->tf_regs).reg_eax,
                                                        (tf->tf_regs).reg_edx,
                                                        (tf->tf_regs).reg_ecx,
                                                        (tf->tf_regs).reg_ebx,
                                                        (tf->tf_regs).reg_edi,
                                                        (tf->tf_regs).reg_esi);
                                return ;
                        }
                default : ; /* do nothing */
        }

        // Handle clock interrupts.
        // LAB 4: Your code here.

        // JAN 30,2011,SUNUS
        if(tf->tf_trapno == IRQ_OFFSET + IRQ_TIMER)
        {
                sched_yield();
                return;
        }
        // Handle spurious interrupts
        // The hardware sometimes raises these because of noise on the
        // IRQ line or other reasons. We don't care.
        if (tf->tf_trapno == IRQ_OFFSET + IRQ_SPURIOUS) {
                cprintf("Spurious interrupt on irq 7\n");
                print_trapframe(tf);
                return;
        }


        // Unexpected trap: The user process or the kernel has a bug.
        print_trapframe(tf);
        if (tf->tf_cs == GD_KT)
                panic("unhandled trap in kernel");
        else {
                env_destroy(curenv);
                return;
        }
}
Ejemplo n.º 19
0
Archivo: trap.c Proyecto: joe-cai/jos
static void
trap_dispatch(struct Trapframe *tf)
{
    // Handle processor exceptions.
    // LAB 3: Your code here.
    if (tf->tf_trapno == T_BRKPT) {
	print_trapframe(tf);
	// cprintf("Breakpoint!\n");
	while (1)
	    monitor(NULL);
    } else if (tf->tf_trapno == T_PGFLT) {
	page_fault_handler(tf);
	return;
    } else if (tf->tf_trapno == T_SYSCALL) {
	uint32_t syscallno;
	uint32_t a1, a2, a3, a4, a5;
	syscallno = tf->tf_regs.reg_eax;
	a1 = tf->tf_regs.reg_edx;
	a2 = tf->tf_regs.reg_ecx;
	a3 = tf->tf_regs.reg_ebx;
	a4 = tf->tf_regs.reg_edi;
	a5 = tf->tf_regs.reg_esi;
	int32_t ret = syscall(syscallno, a1, a2, a3, a4, a5);
	tf->tf_regs.reg_eax = ret;
	return;
    }

    // Handle spurious interrupts
    // The hardware sometimes raises these because of noise on the
    // IRQ line or other reasons. We don't care.
    if (tf->tf_trapno == IRQ_OFFSET + IRQ_SPURIOUS) {
	cprintf("Spurious interrupt on irq 7\n");
	print_trapframe(tf);
	return;
    }

    // Handle clock interrupts. Don't forget to acknowledge the
    // interrupt using lapic_eoi() before calling the scheduler!
    // LAB 4: Your code here.
    if (tf->tf_trapno == IRQ_OFFSET + IRQ_TIMER) {
	time_tick();
	lapic_eoi(); /* what's that? */
	sched_yield();
    }

    // Handle keyboard and serial interrupts.
    // LAB 5: Your code here.
    if (tf->tf_trapno == IRQ_OFFSET + IRQ_KBD) {
	kbd_intr();
	return;
    }
    if (tf->tf_trapno == IRQ_OFFSET + IRQ_SERIAL) {
	serial_intr();
	return;
    }

    // Unexpected trap: The user process or the kernel has a bug.
    print_trapframe(tf);
    if (tf->tf_cs == GD_KT)
	panic("unhandled trap in kernel");
    else {
	env_destroy(curenv);
	return;
    }
}
Ejemplo n.º 20
0
void int0E(registers* regs) {

    page_fault_handler(regs->errCode);
    return;
}
Ejemplo n.º 21
0
static void
trap_dispatch(struct Trapframe *tf)
{
	// Handle processor exceptions.
	// LAB 3: Your code here.
//<<<<<<< HEAD

	// Handle spurious interrupts
	// The hardware sometimes raises these because of noise on the
	// IRQ line or other reasons. We don't care.
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_SPURIOUS) {
		cprintf("Spurious interrupt on irq 7\n");
		print_trapframe(tf);
		return;
	}
//cprintf("entering trap dispathc\n");
	// Handle clock interrupts. Don't forget to acknowledge the
	// interrupt using lapic_eoi() before calling the scheduler!
	// LAB 4: Your code here.

//<<<<<<< HEAD
	// Add time tick increment to clock interrupts.
	// Be careful! In multiprocessors, clock interrupts are
	// triggered on every CPU.
	// LAB 6: Your code here.


//=======
//<<<<<<< HEAD
//>>>>>>> lab5
	// Handle keyboard and serial interrupts.
	// LAB 5: Your code here.
	if(tf->tf_trapno==IRQ_OFFSET+IRQ_KBD)
	{
		//cprintf("IRQ_OFFSET+IRQ_KBD trap\n");
		kbd_intr();
		return;
	}
	if(tf->tf_trapno==IRQ_OFFSET+IRQ_SERIAL)
        {
                //cprintf("IRQ_OFFSET+IRQ_serial trap\n");
                serial_intr();
                return;
        }
//=======
//=======
	if(tf->tf_trapno==T_PGFLT)
	{
//		cprintf("pagefault handler\n");
		page_fault_handler(tf);
		return;
	} else if((tf->tf_trapno==T_GPFLT)) {
		print_trapframe(tf);
		return;
	}
	else if(tf->tf_trapno==T_BRKPT)
        {
//                cprintf("T_BRKPT");
		monitor(tf);
                return;
        }
	else if(tf->tf_trapno==T_SYSCALL)
	{//	cprintf("calling syscal'\n");
		tf->tf_regs.reg_rax =syscall(tf->tf_regs.reg_rax,tf->tf_regs.reg_rdx,tf->tf_regs.reg_rcx,tf->tf_regs.reg_rbx,tf->tf_regs.reg_rdi,tf->tf_regs.reg_rsi);
	//	cprintf("syscall exit\n");
		return;
	}
//>>>>>>> lab3
//>>>>>>> lab4
	// Unexpected trap: The user process or the kernel has a bug.
	else if(tf->tf_trapno == IRQ_OFFSET + IRQ_TIMER)
	{
		lapic_eoi();
		time_tick();
		sched_yield();
	}
	print_trapframe(tf);
	if (tf->tf_cs == GD_KT)
		panic("unhandled trap in kernel");
	else {
		cprintf("destroy env\n");
		env_destroy(curenv);
		return;
	}
//	cprintf("exiting trap_dispatch\n");
}
Ejemplo n.º 22
0
static void
trap_dispatch(struct Trapframe *tf)
{
	uint32_t temp;

	// Switch on the trap number
	switch(tf->tf_trapno) {
	case T_DEBUG:
		// Unset the step flag in EFLAGS before entering the monitor
		tf->tf_eflags &= ~FL_TF;
	case T_BRKPT:
		// Use breakpoints and debug interrupts  as a shortcut to
		//  start the kernel monitor
		monitor(tf);
		return;
	case T_PGFLT:
		// Handle page faults with their own handler.
		page_fault_handler(tf);
		return;
	case T_SYSCALL:
		// For system calls, pass arguments to the syscall handler
		//  and return the result in register EAX.
		//
		// The number must be stored away, and tf->tf_regs.reg_eax
		//  set to 0 before the call.  This is because some system
		//  calls such as sys_ipc_recv don't return (due to a call to
		//  sched_yield()), but expect to return 0 for the return value.
		//  If reg_eax is not cleared, then whatever is in it might be
		//  mistaken for the return value. -_-
		temp = tf->tf_regs.reg_eax;
		tf->tf_regs.reg_eax = 0;
		tf->tf_regs.reg_eax = syscall(temp,
					      tf->tf_regs.reg_edx,
					      tf->tf_regs.reg_ecx,
					      tf->tf_regs.reg_ebx,
					      tf->tf_regs.reg_edi,
					      tf->tf_regs.reg_esi);
		return;
	}

	// Handle spurious interrupts
	// The hardware sometimes raises these because of noise on the
	// IRQ line or other reasons. We don't care.
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_SPURIOUS) {
		cprintf("Spurious interrupt on irq 7\n");
		print_trapframe(tf);
		return;
	}

	// Handle clock interrupts. Don't forget to acknowledge the
	// interrupt using lapic_eoi() before calling the scheduler!
	if(tf->tf_trapno == IRQ_OFFSET+IRQ_TIMER) {
		// Timer interrupts should cause the scheduler to be run
		lapic_eoi();
		sched_yield();
	}

	// Handle keyboard and serial interrupts.
	if(tf->tf_trapno == IRQ_OFFSET+IRQ_KBD) {
		// kern/console.c function that handles the keyboard
		kbd_intr();
		return;
	}

	if(tf->tf_trapno == IRQ_OFFSET+IRQ_SERIAL) {
		// kern/console.c function that handles serial input
		serial_intr();
		return;
	}

	// Unexpected trap: The user process or the kernel has a bug.
	print_trapframe(tf);
	if (tf->tf_cs == GD_KT)
		panic("unhandled trap in kernel");
	else {
		env_destroy(curenv);
		return;
	}
}
Ejemplo n.º 23
0
static void
trap_dispatch(struct Trapframe *tf)
{
	// Handle processor exceptions.
	// LAB 3: Your code here.
	switch(tf->tf_trapno) {
	case T_PGFLT:
		page_fault_handler(tf);
		return;
	case T_BRKPT:
	case T_DEBUG:
		monitor(tf);
		return;
	case T_SYSCALL:
		tf->tf_regs.reg_eax = syscall(tf->tf_regs.reg_eax, // syscall #
					tf->tf_regs.reg_edx, // arg1
					tf->tf_regs.reg_ecx, // arg2
					tf->tf_regs.reg_ebx, // arg3
					tf->tf_regs.reg_edi, // arg4
					tf->tf_regs.reg_esi);// arg5
		return;
	}

	// Handle spurious interrupts
	// The hardware sometimes raises these because of noise on the
	// IRQ line or other reasons. We don't care.
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_SPURIOUS) {
		cprintf("Spurious interrupt on irq 7\n");
		print_trapframe(tf);
		return;
	}

	// Handle clock interrupts. Don't forget to acknowledge the
	// interrupt using lapic_eoi() before calling the scheduler!
	// Add time tick increment to clock interrupts.
	// Be careful! In multiprocessors, clock interrupts are
	// triggered on every CPU.
	// LAB 4: Your code here.
	// LAB 6: Your code here.
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_TIMER) {
		time_tick();
		lapic_eoi();
		sched_yield();
		return;
	}

	// Handle keyboard and serial interrupts.
	// LAB 7: Your code here.
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_SERIAL) {
		serial_intr();
		return;
	}

	if (tf->tf_trapno == IRQ_OFFSET + IRQ_KBD) {
		kbd_intr();
		return;
	}

	// Unexpected trap: The user process or the kernel has a bug.
	print_trapframe(tf);
	if (tf->tf_cs == GD_KT)
		panic("unhandled trap in kernel");
	else {
		env_destroy(curenv);
		return;
	}
}
Ejemplo n.º 24
0
static void
trap_dispatch(struct Trapframe *tf)
{
	// Handle processor exceptions.
	// LAB 3: Your code here.
	int32_t sc_ret;

	assert(tf != NULL);
	switch (tf->tf_trapno) {
		case T_PGFLT:
			page_fault_handler(tf);
			return;
		case T_BRKPT:
		case T_DEBUG:
			/* break into the kernel monitor */
			while (1) {
				monitor(tf);
			}
			return;
		case T_SYSCALL:
			sc_ret = syscall(tf->tf_regs.reg_eax, tf->tf_regs.reg_edx,
					tf->tf_regs.reg_ecx, tf->tf_regs.reg_ebx,
					tf->tf_regs.reg_edi, tf->tf_regs.reg_esi);
			tf->tf_regs.reg_eax = sc_ret;
			return;

		default:
			break;
	}
	
	// Handle clock interrupts.
	// LAB 4: Your code here.

	// Add time tick increment to clock interrupts.
	// LAB 6: Your code here.
	switch (tf->tf_trapno) {
		case (IRQ_OFFSET + IRQ_TIMER):
			time_tick();
			sched_yield();
			return;
		case (IRQ_OFFSET + IRQ_KBD):
			//cprintf("Keyboard interrupt on irq %d\n", IRQ_KBD);
			kbd_intr();
			return;
		case (IRQ_OFFSET + IRQ_SERIAL):
			//cprintf("Serial interrupt on irq %d\n", IRQ_SERIAL);
			serial_intr();
			return;

		default:
			break;
	}

	if (tf->tf_trapno == (IRQ_OFFSET + e100_irq_line)) {
		cprintf("E100 interrupt on irq %d\n", e100_irq_line);
		return;
	}

	// Handle spurious interrupts
	// The hardware sometimes raises these because of noise on the
	// IRQ line or other reasons. We don't care.
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_SPURIOUS) {
		cprintf("Spurious interrupt on irq 7\n");
		print_trapframe(tf);
		return;
	}


	// Handle keyboard and serial interrupts.
	// LAB 7: Your code here.

	// Unexpected trap: The user process or the kernel has a bug.
	print_trapframe(tf);
	if (tf->tf_cs == GD_KT)
		panic("unhandled trap in kernel");
	else {
		env_destroy(curenv);
		return;
	}
}
Ejemplo n.º 25
0
static void
trap_dispatch(struct Trapframe *tf)
{
	// Handle processor exceptions.
	// LAB 3: Your code here.
	//print_trapframe(tf);
	if(tf->tf_trapno == T_PGFLT)
    {
        page_fault_handler(tf);
    }
    else if(tf->tf_trapno == T_BRKPT)
    {
        monitor(tf);
    }
    else if(tf->tf_trapno == T_SYSCALL)
    {
        tf->tf_regs.reg_rax = syscall(tf->tf_regs.reg_rax, tf->tf_regs.reg_rdx,
                        tf->tf_regs.reg_rcx, tf->tf_regs.reg_rbx,
                        tf->tf_regs.reg_rdi, tf->tf_regs.reg_rsi);
        return;
    }

	// Handle spurious interrupts
	// The hardware sometimes raises these because of noise on the
	// IRQ line or other reasons. We don't care.
	if (tf->tf_trapno == IRQ_OFFSET + IRQ_SPURIOUS) {
		cprintf("Spurious interrupt on irq 7\n");
		print_trapframe(tf);
		return;
	}

	// Handle clock interrupts. Don't forget to acknowledge the
	// interrupt using lapic_eoi() before calling the scheduler!
	// LAB 4: Your code here.


	// Handle keyboard and serial interrupts.
	// LAB 5: Your code here.
	else if(tf->tf_trapno == (IRQ_OFFSET + IRQ_TIMER))
	{
		lapic_eoi();
		sched_yield();
	}
	else if(tf->tf_trapno == (IRQ_OFFSET + IRQ_KBD))
	{
		kbd_intr();
		sched_yield();
	}
	else if(tf->tf_trapno == (IRQ_OFFSET + IRQ_SERIAL))
	{
		serial_intr();
		sched_yield();
	}
	// Unexpected trap: The user process or the kernel has a bug.
	print_trapframe(tf);
	if (tf->tf_cs == GD_KT)
		panic("unhandled trap in kernel");
	else {
		env_destroy(curenv);
		return;
	}
}