/* * * cons_getc - return the next input character from console, * or 0 if none waiting. * */ int cons_getc(void) { int c = 0; bool intr_flag; local_intr_save(intr_flag); { // poll for any pending input characters, // so that this function works even when interrupts are disabled // (e.g., when called from the kernel monitor). #ifdef USE_UART serial_intr(); #endif #ifdef HAS_SDS if (check_sds() && is_debugging()) sds_poll_proc(); sds_intr(); #endif //kbd_intr(); // grab the next character from the input buffer. if (cons.rpos != cons.wpos) { c = cons.buf[cons.rpos++]; if (cons.rpos == CONSBUFSIZE) { cons.rpos = 0; } } } local_intr_restore(intr_flag); return c; }
char cons_getc(void) { int c; // poll for any pending input characters, // so that this function works even when interrupts are disabled // (e.g., when called from the kernel monitor). serial_intr(); keyboard_intr(); spinlock_acquire(&cons_lk); // grab the next character from the input buffer. if (cons.rpos != cons.wpos) { c = cons.buf[cons.rpos++]; if (cons.rpos == CONSOLE_BUFFER_SIZE) cons.rpos = 0; spinlock_release(&cons_lk); return c; } spinlock_release(&cons_lk); return 0; }
// return the next input character from the console, or 0 if none waiting int cons_getc(void) { int c; // poll for any pending input characters, // so that this function works even when interrupts are disabled // (e.g., when called from the kernel monitor). serial_intr(); kbd_intr(); // grab the next character from the input buffer. if (cons.rpos != cons.wpos) { c = cons.buf[cons.rpos++]; if (cons.rpos == CONSBUFSIZE) cons.rpos = 0; return c; } return 0; }
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; } }
/* * * cons_getc - return the next input character from console, * or 0 if none waiting. * */ int cons_getc(void) { int c = 0; unsigned long intr_flag; local_irq_save(intr_flag); { // poll for any pending input characters, // so that this function works even when interrupts are disabled // (e.g., when called from the kernel monitor). serial_intr(); kbd_intr(); // grab the next character from the input buffer. if (cons.rpos != cons.wpos) { c = cons.buf[cons.rpos ++]; if (cons.rpos == CONSBUFSIZE) { cons.rpos = 0; } } } local_irq_restore(intr_flag); return c; }
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; } }
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; } }
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; } }
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; } }
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; } }
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; } }
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; } }
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"); }
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; } }
static void trap_dispatch(struct Trapframe *tf) { //cprintf("[%08x] user fault va %08x ip %08x\n", // curenv->env_id, fault_va, tf->tf_eip); //cprintf("now:%x\n",tf->tf_cs); // 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; } // Handle keyboard and serial interrupts. // LAB 5: 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. //Check for fault in kernel mode 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; } if (tf->tf_trapno == T_PGFLT) page_fault_handler(tf); if (tf->tf_trapno == T_BRKPT) monitor(tf); print_trapframe(tf); if (tf->tf_cs == GD_KT) panic("unhandled trap in kernel"); else { env_destroy(curenv); return; } }
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 ---------------------------------------------------------------------------------------- // Handle keyboard and serial interrupts. // LAB 5: Your code here. //----------------------------------------------------------------------- Lab5 ----------------------------- if (tf->tf_trapno == IRQ_OFFSET + IRQ_KBD) { kbd_intr(); return; } if (tf->tf_trapno == IRQ_OFFSET + IRQ_SERIAL) { serial_intr(); return ; } //----------------------------------------------------------------------- Lab5 ----------------------------- // 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; } }
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; } }