static void print_ticks() { cprintf("%d ticks\n",TICK_NUM); }
void Om1(int x,int y) { gotoxy(x,y); textcolor(LIGHTCYAN); cprintf("%c",1); }
void main () { volatile sBSP430hplTIMER * const hpl = xBSP430hplLookupTIMER(BSP430_PERIPH_TA0); unsigned long ta0_Hz; unsigned int delta_ta0; const struct sLPMconfig * lcp = lpm_configs; const struct sLPMconfig * const elcp = lpm_configs + sizeof(lpm_configs)/sizeof(*lpm_configs); vBSP430platformInitialize_ni(); (void)iBSP430consoleInitialize(); TA0CTL = TASSEL_1 | MC_2 | TACLR; ta0_Hz = ulBSP430timerFrequency_Hz_ni(BSP430_PERIPH_TA0); #if 0 /* This sequence eliminates the wakeup delay on the MSP430F5438A. * The ramifications of doing this are to be found in the Power * Management Module and Supply Voltage Supervisor chapter of the * 5xx/6xx Family User's Guide, in the section "SVS and SVM * Performance Modes and Wakeup Times". * * Also check MCU errata related to the PMM. THere are several that * appear relevant when changing the module from its power-up * state. */ PMMCTL0_H = PMMPW_H; #if 1 /* This variant works */ SVSMLCTL &= ~(SVSLE | SVMLE); #else /* This appears to have no effect, though it should work. */ SVSMLCTL |= SVSLFP; #endif PMMCTL0_H = !PMMPW_H; #endif BSP430_CORE_ENABLE_INTERRUPT(); cputs("\n\nTimer LPM wake delay test\n"); delta_ta0 = ta0_Hz / 4; cprintf("TA0 is at %lu Hz; sleep time %u ticks\n", ta0_Hz, delta_ta0); cprintf("Standard mode SR is %04x\n", __read_status_register()); cprintf("SR bits: SCG0 %04x ; SCG1 %04x\n", SCG0, SCG1); cprintf("LPM exit from ISRs clears: %04x\n", BSP430_CORE_LPM_EXIT_MASK); cputs("LPMx CCR0 CAP0 Delta0 CCR1 CAP1 Delta1 SR"); while (lcp < elcp) { unsigned int tar; cprintf("%s: ", lcp->tag); BSP430_CORE_DISABLE_INTERRUPT(); ta0r = 0; hpl->cctl[0] = CCIE; tar = uiBSP430timerAsyncCounterRead_ni(hpl); hpl->ccr[0] = tar + delta_ta0; BSP430_CORE_LPM_ENTER_NI(lcp->lpm_bits); cprintf("%5u %5u %5u ", hpl->ccr[0], ta0r, ta0r-hpl->ccr[0]); BSP430_CORE_DISABLE_INTERRUPT(); ta0r = 0; hpl->cctl[1] = CCIE; tar = uiBSP430timerAsyncCounterRead_ni(hpl); hpl->ccr[1] = tar + delta_ta0; BSP430_CORE_LPM_ENTER_NI(lcp->lpm_bits); cprintf("%5u %5u %5u ", hpl->ccr[1], ta0r, ta0r-hpl->ccr[1]); cprintf("%04x\n", __read_status_register()); ++lcp; } cprintf("Done\n"); }
void entry() { char ch; clrscr(); ptr=fopen("shop.dat","a+b"); ch='y'; while(ch=='y') { clrscr(); design(); textcolor(14); t(); gotoxy(14,3); cprintf("\xDB\xDB\xDB\xDB\xDB\xB2 PURSHASE \xB2\xDB\xDB\xDB\xDB\xDB "); { gotoxy(7,5); cprintf("\xDB\xDB\xB2 ENTER PRODUCT ID : "); ventry(temp.id,1); // flushall(); gotoxy(7,7); cprintf("\xDB\xDB\xB2 ENTER DESCRIPTION : "); ventry(temp.desc,0); flushall(); gotoxy(7,9); cprintf("\xDB\xDB\xB2 ENTER RACK NO : "); ventry(a,1); temp.rack= atoi(a); flushall(); gotoxy(7,11); cprintf("\xDB\xDB\xB2 ENTER CABNIT NO : "); ventry(a,1); temp.cabnit= atoi(a); // flushall(); gotoxy(7,13); /////////////////////// cprintf("\xDB\xDB\xB2 ENTER UNIT COST :$ "); ventry(a,1); temp.unit= atof(a); flushall(); gotoxy(7,15); cprintf("\xDB\xDB\xB2 ENTER SALE PRICE :$ "); ventry(a,1); temp.sale= atof(a); flushall(); gotoxy(7,17); cprintf("\xDB\xDB\xB2 ENTER QUANTITY : "); ventry(a,1); temp.quantity= atoi(a); flushall(); gotoxy(7,18); cprintf("====================================="); temp.total=temp.quantity*temp.sale; textcolor(10); gotoxy(10,20); cprintf("\xB2\xDB\xB2 TOTAL PRICE = $ %.2f",temp.total); temp.cost=(temp.unit*temp.quantity); gotoxy(40,20); cprintf("\xDB\xB2 TOTAL COST = $ %.2f",temp.cost); } fwrite(&temp,sizeof(temp),1,ptr); textcolor(10); gotoxy(10,23); cprintf("More entries [y/n]"); ch=getche(); } fclose(ptr); }
/***************************main menu*************************************/ menu() { int x; do { { clrscr(); design(); t(); textcolor(WHITE); gotoxy(24,3); cprintf("\xDB\xDB\xDB\xDB\xB2 LYDIA'S DEPARTMENT STORE \xB2\xDB\xDB\xDB\xDB"); gotoxy(3,4); cprintf("--------------------------------------------------------------------------"); gotoxy(35,5); cprintf("MAIN MENU"); gotoxy(26,8); cprintf(" 1 - INFORMATION ABOUT PRODUCTS "); gotoxy(26,9); cprintf(" 2 - ENTER PURCHASE RECORDS "); gotoxy(26,10); cprintf(" 3 - ENTER PRODUCTS TO BE SALE "); gotoxy(26,11); cprintf(" 4 - SEARCH FOR RECORD "); gotoxy(26,12); cprintf(" 5 - DELETE RECORD FROM STORE DATABASE "); gotoxy(26,13); cprintf(" 6 - VIEW SALES , PURCHASE & PROFIT REPORT "); gotoxy(26,14); cprintf(" 7 - PRINT RECORDS "); gotoxy(26,15); cprintf(" 8 - BAR GRAPH OF QUANTITY / PROFIT "); gotoxy(26,16); cprintf(" 9 - RETRIEVE INFORMATION "); gotoxy(26,17); cprintf(" H - HELP "); gotoxy(26,18); cprintf(" E - EXIT "); gotoxy(26,23); // cprintf("ENTER YOUR CHOICE :: "); gotoxy(47,23); x=toupper(getch()); switch(x) { case '1': infor(); break; case '2': entry(); break; case '3': edit(); break; case '4': search(); break; case '5': del(); break; case '6': report2(); break; case '7': print(); break; case 'h': case'H': help(); break; case'8': graph1(); break; case '9': display(); break; case 'e': case 'E': exit(0); break; default: clrscr(); design(); gotoxy(17,12); printf("\a\xDB\xB2 WRONG ENTRY : PRESS ANY KEY AND TRY AGAIN"); getche(); } } } while((x!='e')||(x!='E')); return x; }
void page_fault_handler(struct Trapframe *tf) { uint64_t fault_va; // Read processor's CR2 register to find the faulting address fault_va = rcr2(); // Handle kernel-mode page faults. // LAB 3: Your code here. if (!(tf->tf_cs & 0x3)) { print_trapframe(tf); panic("unhandled trap in kernel"); } // We've already handled kernel-mode exceptions, so if we get here, // the page fault happened in user mode. // Call the environment's page fault upcall, if one exists. Set up a // page fault stack frame on the user exception stack (below // UXSTACKTOP), then branch to curenv->env_pgfault_upcall. // // The page fault upcall might cause another page fault, in which case // we branch to the page fault upcall recursively, pushing another // page fault stack frame on top of the user exception stack. // // The trap handler needs one word of scratch space at the top of the // trap-time stack in order to return. In the non-recursive case, we // don't have to worry about this because the top of the regular user // stack is free. In the recursive case, this means we have to leave // an extra word between the current top of the exception stack and // the new stack frame because the exception stack _is_ the trap-time // stack. // // // If there's no page fault upcall, the environment didn't allocate a // page for its exception stack or can't write to it, or the exception // stack overflows, then destroy the environment that caused the fault. // Note that the grade script assumes you will first check for the page // fault upcall and print the "user fault va" message below if there is // none. The remaining three checks can be combined into a single test. // // Hints: // user_mem_assert() and env_run() are useful here. // To change what the user environment runs, modify 'curenv->env_tf' // (the 'tf' variable points at 'curenv->env_tf'). if (curenv->env_pgfault_upcall) { struct UTrapframe *utexp; if (tf->tf_rsp <= UXSTACKTOP-1 && tf->tf_rsp >= UXSTACKTOP-PGSIZE) { utexp = (struct UTrapframe*) (tf->tf_rsp - sizeof(struct UTrapframe) - 8); } else { utexp = (struct UTrapframe*)(UXSTACKTOP - sizeof(struct UTrapframe)); } //storing that 64 bit thingy.(this was tough!, I'm weak with bits ;) ) //(time frame) to be stored...but how does it get pushed into the stack...you assign it to uxstacktop //thats brilliant. Thank you! thank you...wait a minute...see if it overflows! user_mem_assert(curenv, (void*)utexp, sizeof(struct UTrapframe), PTE_W|PTE_U); utexp->utf_fault_va = fault_va; utexp->utf_err = tf->tf_err; utexp->utf_regs = tf->tf_regs; utexp->utf_rip = tf->tf_rip; utexp->utf_eflags = tf->tf_eflags; utexp->utf_rsp = tf->tf_rsp; //How do i run the upcall...set the rip...thats nice...thank you exercise 10 :) tf->tf_rip = (uint64_t)curenv->env_pgfault_upcall; tf->tf_rsp = (uint64_t)utexp; env_run(curenv); } // LAB 4: Your code here. // Destroy the environment that caused the fault. cprintf("[%08x] user fault va %08x ip %08x\n", curenv->env_id, fault_va, tf->tf_rip); print_trapframe(tf); env_destroy(curenv); }
void main() { int i=0,j,achou=0,A,B=2; char labir[12]; person rato,ratotemp; clrscr(); do { gotoxy(30,5); printf("[1] N¡vel F cil"); gotoxy(30,6); printf("[2] N¡vel Normal"); gotoxy(30,7); printf("[3] N¡vel Dif¡cil"); gotoxy(30,8); printf("[4] Desafio Especial"); gotoxy(30,9); printf("[5] Outro"); gotoxy(30,11); printf("Op‡Æo: "); scanf("%d",&i); switch(i) { case 1:strcpy(labir,"labiresp.txt");break; case 2:strcpy(labir,"labir.txt");break; case 3:strcpy(labir,"labir3.txt");break; case 4:strcpy(labir,"labir2.txt");break; case 5: { gotoxy(30,20); printf("Digite o nome do arquivo: "); fflush(stdin); gets(&labir); } } }while(i==0); Labirin(labir); Inicio(); B=2; A=1; IniciaPilha(); rato=IniciaPerson(rato); push(rato); do { A=pilha.topo+1; if (rato.x>X) { rato.x=X;} if (rato.y>Y) { rato.y=Y;} if (pilha.topo>23) { B=65; A=pilha.topo-23; if (pilha.topo>44) { B=2; A=pilha.topo-44; if (pilha.topo>63) { B=65; A=pilha.topo-63; if (pilha.topo>84) { B=2; A=pilha.topo-84; } } } } gotoxy(rato.y+20,rato.x+8); textcolor(7); cprintf("©"); if (pilha.topo>1) { gotoxy(ratotemp.y+20,ratotemp.x+8); cprintf(" "); } gotoxy(B,A); cprintf("%d,%d",pilha.vetorx[pilha.topo],pilha.vetory[pilha.topo]); if ((rato.x==X)&&(rato.y==Y)) { gotoxy(B,A); cprintf("ACHOU!!!"); achou=1; } ratotemp=rato; rato=Proxima(rato); getch(); }while(achou!=1); clrscr(); }
void _main(void) { //int InitFreeFrames = sys_calculate_free_frames() ; char Line[255] ; char Chose ; int Iteration = 0 ; do { int InitFreeFrames = sys_calculate_free_frames() + sys_calculate_modified_frames(); Iteration++ ; // cprintf("Free Frames Before Allocation = %d\n", sys_calculate_free_frames()) ; sys_disable_interrupt(); readline("Enter the number of elements: ", Line); int NumOfElements = strtol(Line, NULL, 10) ; int *Elements = malloc(sizeof(int) * NumOfElements) ; Elements[NumOfElements] = 10 ; // cprintf("Free Frames After Allocation = %d\n", sys_calculate_free_frames()) ; cprintf("Choose the initialization method:\n") ; cprintf("a) Ascending\n") ; cprintf("b) Descending\n") ; cprintf("c) Semi random\nSelect: ") ; Chose = getchar() ; cputchar(Chose); cputchar('\n'); sys_enable_interrupt(); int i ; switch (Chose) { case 'a': InitializeAscending(Elements, NumOfElements); break ; case 'b': InitializeDescending(Elements, NumOfElements); break ; case 'c': InitializeSemiRandom(Elements, NumOfElements); break ; default: InitializeSemiRandom(Elements, NumOfElements); } QuickSort(Elements, NumOfElements); // PrintElements(Elements, NumOfElements); uint32 Sorted = CheckSorted(Elements, NumOfElements); if(Sorted == 0) panic("The array is NOT sorted correctly") ; else { cprintf("\n===============================================\n") ; cprintf("Congratulations!! The array is sorted correctly\n") ; cprintf("===============================================\n\n") ; } // cprintf("Free Frames After Calculation = %d\n", sys_calculate_free_frames()) ; cprintf("Freeing the Heap...\n\n") ; free(Elements) ; ///======================================================================== sys_disable_interrupt(); cprintf("Do you want to repeat (y/n): ") ; Chose = getchar() ; cputchar(Chose); cputchar('\n'); cputchar('\n'); sys_enable_interrupt(); } while (Chose == 'y'); }
static void check_swap(void) { //backup mem env int ret, count = 0, total = 0, i; list_entry_t *le = &free_list; while ((le = list_next(le)) != &free_list) { struct Page *p = le2page(le, page_link); assert(PageProperty(p)); count ++, total += p->property; } assert(total == nr_free_pages()); cprintf("BEGIN check_swap: count %d, total %d\n",count,total); //now we set the phy pages env struct mm_struct *mm = mm_create(); assert(mm != NULL); extern struct mm_struct *check_mm_struct; assert(check_mm_struct == NULL); check_mm_struct = mm; pde_t *pgdir = mm->pgdir = boot_pgdir; assert(pgdir[0] == 0); struct vma_struct *vma = vma_create(BEING_CHECK_VALID_VADDR, CHECK_VALID_VADDR, VM_WRITE | VM_READ); assert(vma != NULL); insert_vma_struct(mm, vma); //setup the temp Page Table vaddr 0~4MB cprintf("setup Page Table for vaddr 0X1000, so alloc a page\n"); pte_t *temp_ptep=NULL; temp_ptep = get_pte(mm->pgdir, BEING_CHECK_VALID_VADDR, 1); assert(temp_ptep!= NULL); cprintf("setup Page Table vaddr 0~4MB OVER!\n"); for (i=0;i<CHECK_VALID_PHY_PAGE_NUM;i++) { check_rp[i] = alloc_page(); assert(check_rp[i] != NULL ); assert(!PageProperty(check_rp[i])); } list_entry_t free_list_store = free_list; list_init(&free_list); assert(list_empty(&free_list)); //assert(alloc_page() == NULL); unsigned int nr_free_store = nr_free; nr_free = 0; for (i=0;i<CHECK_VALID_PHY_PAGE_NUM;i++) { free_pages(check_rp[i],1); } assert(nr_free==CHECK_VALID_PHY_PAGE_NUM); cprintf("set up init env for check_swap begin!\n"); //setup initial vir_page<->phy_page environment for page relpacement algorithm pgfault_num=0; check_content_set(); assert( nr_free == 0); for(i = 0; i<MAX_SEQ_NO ; i++) swap_out_seq_no[i]=swap_in_seq_no[i]=-1; for (i= 0;i<CHECK_VALID_PHY_PAGE_NUM;i++) { check_ptep[i]=0; check_ptep[i] = get_pte(pgdir, (i+1)*0x1000, 0); //cprintf("i %d, check_ptep addr %x, value %x\n", i, check_ptep[i], *check_ptep[i]); assert(check_ptep[i] != NULL); assert(pte2page(*check_ptep[i]) == check_rp[i]); assert((*check_ptep[i] & PTE_P)); } cprintf("set up init env for check_swap over!\n"); // now access the virt pages to test page relpacement algorithm ret=check_content_access(); assert(ret==0); //restore kernel mem env for (i=0;i<CHECK_VALID_PHY_PAGE_NUM;i++) { free_pages(check_rp[i],1); } //free_page(pte2page(*temp_ptep)); free_page(pa2page(pgdir[0])); pgdir[0] = 0; mm->pgdir = NULL; mm_destroy(mm); check_mm_struct = NULL; nr_free = nr_free_store; free_list = free_list_store; le = &free_list; while ((le = list_next(le)) != &free_list) { struct Page *p = le2page(le, page_link); count --, total -= p->property; } cprintf("count is %d, total is %d\n",count,total); //assert(count == 0); cprintf("check_swap() succeeded!\n"); }
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; } }
// interrupt and trap handlers void page_fault_handler(struct Trapframe *tf) { uint32_t fault_va; // Read processor's CR2 register to find the faulting address fault_va = rcr2(); // Handle kernel-mode page faults. // previlage level = 0 if ((tf->tf_cs & 3) == 0){ panic("kernel page fault"); } // LAB 3: Your code here. // We've already handled kernel-mode exceptions, so if we get here, // the page fault happened in user mode. // Call the environment's page fault upcall, if one exists. Set up a // page fault stack frame on the user exception stack (below // UXSTACKTOP), then branch to curenv->env_pgfault_upcall. // // The page fault upcall might cause another page fault, in which case // we branch to the page fault upcall recursively, pushing another // page fault stack frame on top of the user exception stack. // // The trap handler needs one word of scratch space at the top of the // trap-time stack in order to return. In the non-recursive case, we // don't have to worry about this because the top of the regular user // stack is free. In the recursive case, this means we have to leave // an extra word between the current top of the exception stack and // the new stack frame because the exception stack _is_ the trap-time // stack. // // If there's no page fault upcall, the environment didn't allocate a // page for its exception stack or can't write to it, or the exception // stack overflows, then destroy the environment that caused the fault. // Note that the grade script assumes you will first check for the page // fault upcall and print the "user fault va" message below if there is // none. The remaining three checks can be combined into a single test. // // Hints: // user_mem_assert() and env_run() are useful here. // To change what the user environment runs, modify 'curenv->env_tf' // (the 'tf' variable points at 'curenv->env_tf'). // LAB 4: Your code here. // Now we are in kernel mode if (curenv->env_pgfault_upcall != NULL){ struct UTrapframe *utf; // Check tf_esp is in UXSTACK // -4, scratch space to save eip return address if (tf->tf_esp >= UXSTACKTOP - PGSIZE && tf->tf_esp < UXSTACKTOP){ utf = (struct UTrapframe *)(tf->tf_esp - sizeof(struct UTrapframe) - 4); } else { utf = (struct UTrapframe *)(UXSTACKTOP - sizeof(struct UTrapframe)); } // Check permission user_mem_assert(curenv, (void *)utf, sizeof(struct UTrapframe), PTE_U | PTE_W); // dump Trapframe info to UTrapframe utf->utf_fault_va = fault_va; utf->utf_err = tf->tf_err; utf->utf_regs = tf->tf_regs; utf->utf_eip = tf->tf_eip; utf->utf_eflags = tf->tf_eflags; utf->utf_esp = tf->tf_esp; // set eip to env_pgfault_upcall curenv->env_tf.tf_eip = (uint32_t)curenv->env_pgfault_upcall; curenv->env_tf.tf_esp = (uint32_t)utf; // Debug info // cprintf("Dispatch to user-mode page fault handler: fault_va %08x\n", fault_va); // if (fault_va >= USTACKTOP - PGSIZE && fault_va < USTACKTOP) cprintf("pgfautl on stack\n"); env_run(curenv); } else { cprintf("ERROR: %x env_pgfault_upcall is NULL\n", curenv->env_id); } // Destroy the environment that caused the fault. cprintf("[%08x] user fault va %08x ip %08x\n", curenv->env_id, fault_va, tf->tf_eip); print_trapframe(tf); env_destroy(curenv); }
int mon_backtrace(int argc, char **argv, struct Trapframe *tf) { // Your code here. cprintf("Stack backtrace:\n"); uint32_t ebp = read_ebp(); uint32_t eip; // = read_eip(); struct Eipdebuginfo info; int idxStr; while (ebp != 0) { // print registers cprintf(" ebp %x", ebp); eip = *(uint32_t*)(ebp + 4); cprintf(" eip %x", eip); cprintf(" args %08x", *(uint32_t*)(ebp + 8)); cprintf(" %08x", *(uint32_t*)(ebp + 12)); cprintf(" %08x", *(uint32_t*)(ebp + 16)); cprintf(" %08x", *(uint32_t*)(ebp + 20)); cprintf(" %08x\n", *(uint32_t*)(ebp + 24)); ebp = *(uint32_t*)ebp; // print line numbers debuginfo_eip((uintptr_t)eip, &info); cprintf(" %s", info.eip_file); cprintf(":%d: ", info.eip_line); for (idxStr = 0; idxStr < info.eip_fn_namelen; idxStr++) cprintf("%c", info.eip_fn_name[idxStr]); cprintf("+%d\n", eip - info.eip_fn_addr); } return 0; }
void _main(void) { //cprintf("hello from the test side!"); int envID = sys_getenvid(); // cprintf("envID = %d\n",envID); volatile struct Env* myEnv; myEnv = &(envs[envID]); char arr[PAGE_SIZE*1024*4]; //("STEP 0: checking Initial WS entries ...\n"); { if( ROUNDDOWN(myEnv->__uptr_pws[0].virtual_address,PAGE_SIZE) != 0x200000) panic("INITIAL PAGE WS entry checking failed! Review size of the WS..!!"); if( ROUNDDOWN(myEnv->__uptr_pws[1].virtual_address,PAGE_SIZE) != 0x201000) panic("INITIAL PAGE WS entry checking failed! Review size of the WS..!!"); if( ROUNDDOWN(myEnv->__uptr_pws[2].virtual_address,PAGE_SIZE) != 0x202000) panic("INITIAL PAGE WS entry checking failed! Review size of the WS..!!"); if( ROUNDDOWN(myEnv->__uptr_pws[3].virtual_address,PAGE_SIZE) != 0x203000) panic("INITIAL PAGE WS entry checking failed! Review size of the WS..!!"); if( ROUNDDOWN(myEnv->__uptr_pws[4].virtual_address,PAGE_SIZE) != 0x204000) panic("INITIAL PAGE WS entry checking failed! Review size of the WS..!!"); if( ROUNDDOWN(myEnv->__uptr_pws[5].virtual_address,PAGE_SIZE) != 0x205000) panic("INITIAL PAGE WS entry checking failed! Review size of the WS..!!"); if( ROUNDDOWN(myEnv->__uptr_pws[6].virtual_address,PAGE_SIZE) != 0x206000) panic("INITIAL PAGE WS entry checking failed! Review size of the WS..!!"); if( ROUNDDOWN(myEnv->__uptr_pws[7].virtual_address,PAGE_SIZE) != 0x800000) panic("INITIAL PAGE WS entry checking failed! Review size of the WS..!!"); if( ROUNDDOWN(myEnv->__uptr_pws[8].virtual_address,PAGE_SIZE) != 0x801000) panic("INITIAL PAGE WS entry checking failed! Review size of the WS..!!"); if( ROUNDDOWN(myEnv->__uptr_pws[9].virtual_address,PAGE_SIZE) != 0x802000) panic("INITIAL PAGE WS entry checking failed! Review size of the WS..!!"); if( ROUNDDOWN(myEnv->__uptr_pws[10].virtual_address,PAGE_SIZE) != 0x803000) panic("INITIAL PAGE WS entry checking failed! Review size of the WS..!!"); if( ROUNDDOWN(myEnv->__uptr_pws[11].virtual_address,PAGE_SIZE) != 0xeebfd000) panic("INITIAL PAGE WS entry checking failed! Review size of the WS..!!"); if( ROUNDDOWN(myEnv->__uptr_pws[12].virtual_address,PAGE_SIZE) != 0xedbfd000) panic("INITIAL PAGE WS entry checking failed! Review size of the WS..!!"); if( myEnv->__uptr_pws[13].empty != 1) panic("INITIAL PAGE WS entry checking failed! Review size of the WS..!!"); if( myEnv->page_last_WS_index != 13) panic("INITIAL PAGE last index checking failed! Review size of the WS..!!"); } int usedDiskPages = sys_pf_calculate_allocated_pages() ; int freePages = sys_calculate_free_frames(); int i=0; for(;i<=PAGE_SIZE;i++) { arr[i] = -1; } i=PAGE_SIZE*1024; for(;i<=(PAGE_SIZE*1024 + PAGE_SIZE);i++) { arr[i] = -1; } i=PAGE_SIZE*1024*2; for(;i<=(PAGE_SIZE*1024*2 + PAGE_SIZE);i++) { arr[i] = -1; } cprintf("STEP A: checking PLACEMENT fault handling ... \n"); { if( arr[0] != -1) panic("PLACEMENT of stack page failed"); if( arr[PAGE_SIZE] != -1) panic("PLACEMENT of stack page failed"); if( arr[PAGE_SIZE*1024] != -1) panic("PLACEMENT of stack page failed"); if( arr[PAGE_SIZE*1025] != -1) panic("PLACEMENT of stack page failed"); if( arr[PAGE_SIZE*1024*2] != -1) panic("PLACEMENT of stack page failed"); if( arr[PAGE_SIZE*1024*2 + PAGE_SIZE] != -1) panic("PLACEMENT of stack page failed"); if( (sys_pf_calculate_allocated_pages() - usedDiskPages) != 5) panic("new stack pages are not written to Page File"); if( (freePages - sys_calculate_free_frames() ) != 9 ) panic("allocated memory size incorrect"); } cprintf("STEP A passed: PLACEMENT fault handling works!\n\n\n"); cprintf("STEP B: checking WS entries ...\n"); { if( ROUNDDOWN(myEnv->__uptr_pws[0].virtual_address,PAGE_SIZE) != 0x200000) panic("PAGE WS entry checking failed... trace it by printing page WS before & after fault"); if( ROUNDDOWN(myEnv->__uptr_pws[1].virtual_address,PAGE_SIZE) != 0x201000) panic("PAGE WS entry checking failed... trace it by printing page WS before & after fault"); if( ROUNDDOWN(myEnv->__uptr_pws[2].virtual_address,PAGE_SIZE) != 0x202000) panic("PAGE WS entry checking failed... trace it by printing page WS before & after fault"); if( ROUNDDOWN(myEnv->__uptr_pws[3].virtual_address,PAGE_SIZE) != 0x203000) panic("PAGE WS entry checking failed... trace it by printing page WS before & after fault"); if( ROUNDDOWN(myEnv->__uptr_pws[4].virtual_address,PAGE_SIZE) != 0x204000) panic("PAGE WS entry checking failed... trace it by printing page WS before & after fault"); if( ROUNDDOWN(myEnv->__uptr_pws[5].virtual_address,PAGE_SIZE) != 0x205000) panic("PAGE WS entry checking failed... trace it by printing page WS before & after fault"); if( ROUNDDOWN(myEnv->__uptr_pws[6].virtual_address,PAGE_SIZE) != 0x206000) panic("PAGE WS entry checking failed... trace it by printing page WS before & after fault"); if( ROUNDDOWN(myEnv->__uptr_pws[7].virtual_address,PAGE_SIZE) != 0x800000) panic("PAGE WS entry checking failed... trace it by printing page WS before & after fault"); if( ROUNDDOWN(myEnv->__uptr_pws[8].virtual_address,PAGE_SIZE) != 0x801000) panic("PAGE WS entry checking failed... trace it by printing page WS before & after fault"); if( ROUNDDOWN(myEnv->__uptr_pws[9].virtual_address,PAGE_SIZE) != 0x802000) panic("PAGE WS entry checking failed... trace it by printing page WS before & after fault"); if( ROUNDDOWN(myEnv->__uptr_pws[10].virtual_address,PAGE_SIZE) != 0x803000) panic("PAGE WS entry checking failed... trace it by printing page WS before & after fault"); if( ROUNDDOWN(myEnv->__uptr_pws[11].virtual_address,PAGE_SIZE) != 0xeebfd000) panic("PAGE WS entry checking failed... trace it by printing page WS before & after fault"); if( ROUNDDOWN(myEnv->__uptr_pws[12].virtual_address,PAGE_SIZE) != 0xedbfd000) panic("PAGE WS entry checking failed... trace it by printing page WS before & after fault"); if( ROUNDDOWN(myEnv->__uptr_pws[13].virtual_address,PAGE_SIZE) != 0xedbfe000) panic("PAGE WS entry checking failed... trace it by printing page WS before & after fault"); if( ROUNDDOWN(myEnv->__uptr_pws[14].virtual_address,PAGE_SIZE) != 0xedffd000) panic("PAGE WS entry checking failed... trace it by printing page WS before & after fault"); if( ROUNDDOWN(myEnv->__uptr_pws[15].virtual_address,PAGE_SIZE) != 0xedffe000) panic("PAGE WS entry checking failed... trace it by printing page WS before & after fault"); if( ROUNDDOWN(myEnv->__uptr_pws[16].virtual_address,PAGE_SIZE) != 0xee3fd000) panic("PAGE WS entry checking failed... trace it by printing page WS before & after fault"); if( ROUNDDOWN(myEnv->__uptr_pws[17].virtual_address,PAGE_SIZE) != 0xee3fe000) panic("PAGE WS entry checking failed... trace it by printing page WS before & after fault"); } cprintf("STEP B passed: WS entries test are correct\n\n\n"); cprintf("STEP C: checking working sets pointer locations...\n"); { if(myEnv->page_last_WS_index != 18) panic("wrong PAGE WS pointer location... trace it by printing page WS before & after fault"); i=PAGE_SIZE*1024*3; for(;i<=(PAGE_SIZE*1024*3+PAGE_SIZE);i++) { arr[i] = -1; } if( arr[PAGE_SIZE*1024*3] != -1) panic("PLACEMENT of stack page failed"); if( arr[PAGE_SIZE*1024*3 + PAGE_SIZE] != -1) panic("PLACEMENT of stack page failed"); if( ROUNDDOWN(myEnv->__uptr_pws[19].virtual_address,PAGE_SIZE) != 0xee7fe000) panic("LAST PAGE WS entry checking failed"); if(myEnv->page_last_WS_index != 0) panic("wrong PAGE WS pointer location... trace it by printing page WS before & after fault"); } cprintf("STEP C passed: pointers reached zero\n\n\n"); cprintf("Congratulations!! Test of PAGE PLACEMENT completed successfully!!\n\n\n"); return; }
// Open req->req_path in mode req->req_omode, storing the Fd page and // permissions to return to the calling environment in *pg_store and // *perm_store respectively. int serve_open(envid_t envid, struct Fsreq_open *req, void **pg_store, int *perm_store) { char path[MAXPATHLEN]; struct File *f; int fileid; int r; struct OpenFile *o; //cprintf("serve_open 6666666\n"); if (debug) cprintf("serve_open %08x %s 0x%x\n", envid, req->req_path, req->req_omode); //cprintf("\nserve_open %08x %s 0x%x\n", envid, req->req_path, req->req_omode); // Copy in the path, making sure it's null-terminated memmove(path, req->req_path, MAXPATHLEN); //cprintf("\nserve_open 8888888\n"); path[MAXPATHLEN-1] = 0; //cprintf("\nserve_open 77777777\n"); // Find an open file ID if ((r = openfile_alloc(&o)) < 0) { if (debug) cprintf("openfile_alloc failed: %e", r); return r; } fileid = r; // Open the file if (req->req_omode & O_CREAT) { if ((r = file_create(path, &f)) < 0) { if (!(req->req_omode & O_EXCL) && r == -E_FILE_EXISTS) goto try_open; if (debug) cprintf("file_create failed: %e", r); return r; } } else { try_open: //cprintf("Opening file for read in open_file\n"); if ((r = file_open(path, &f)) < 0) { if (debug) cprintf("file_open failed: %e", r); return r; } } // Truncate if (req->req_omode & O_TRUNC) { if ((r = file_set_size(f, 0)) < 0) { if (debug) cprintf("file_set_size failed: %e", r); return r; } } // Save the file pointer o->o_file = f; // Fill out the Fd structure o->o_fd->fd_file.id = o->o_fileid; o->o_fd->fd_omode = req->req_omode & O_ACCMODE; o->o_fd->fd_dev_id = devfile.dev_id; o->o_mode = req->req_omode; if (debug) cprintf("sending success, page %08x\n", (uintptr_t) o->o_fd); // Share the FD page with the caller *pg_store = o->o_fd; *perm_store = PTE_P|PTE_U|PTE_W|PTE_SHARE; //lab7 return 0; }
void print_regs(struct PushRegs *regs) { cprintf(" r15 0x%08x\n", regs->reg_r15); cprintf(" r14 0x%08x\n", regs->reg_r14); cprintf(" r13 0x%08x\n", regs->reg_r13); cprintf(" r12 0x%08x\n", regs->reg_r12); cprintf(" r11 0x%08x\n", regs->reg_r11); cprintf(" r10 0x%08x\n", regs->reg_r10); cprintf(" r9 0x%08x\n", regs->reg_r9); cprintf(" r8 0x%08x\n", regs->reg_r8); cprintf(" rdi 0x%08x\n", regs->reg_rdi); cprintf(" rsi 0x%08x\n", regs->reg_rsi); cprintf(" rbp 0x%08x\n", regs->reg_rbp); cprintf(" rbx 0x%08x\n", regs->reg_rbx); cprintf(" rdx 0x%08x\n", regs->reg_rdx); cprintf(" rcx 0x%08x\n", regs->reg_rcx); cprintf(" rax 0x%08x\n", regs->reg_rax); }
// // Check the physical page allocator (page_alloc(), page_free(), // and page_init()). // static void check_page_alloc(void) { struct PageInfo *pp, *pp0, *pp1, *pp2; int nfree; struct PageInfo *fl; char *c; int i; if (!pages) panic("'pages' is a null pointer!"); // check number of free pages for (pp = page_free_list, nfree = 0; pp; pp = pp->pp_link) ++nfree; // should be able to allocate three pages pp0 = pp1 = pp2 = 0; assert((pp0 = page_alloc(0))); assert((pp1 = page_alloc(0))); assert((pp2 = page_alloc(0))); assert(pp0); assert(pp1 && pp1 != pp0); assert(pp2 && pp2 != pp1 && pp2 != pp0); assert(page2pa(pp0) < npages*PGSIZE); assert(page2pa(pp1) < npages*PGSIZE); assert(page2pa(pp2) < npages*PGSIZE); // temporarily steal the rest of the free pages fl = page_free_list; page_free_list = 0; // should be no free memory assert(!page_alloc(0)); // free and re-allocate? page_free(pp0); page_free(pp1); page_free(pp2); pp0 = pp1 = pp2 = 0; assert((pp0 = page_alloc(0))); assert((pp1 = page_alloc(0))); assert((pp2 = page_alloc(0))); assert(pp0); assert(pp1 && pp1 != pp0); assert(pp2 && pp2 != pp1 && pp2 != pp0); assert(!page_alloc(0)); // test flags memset(page2kva(pp0), 1, PGSIZE); page_free(pp0); assert((pp = page_alloc(ALLOC_ZERO))); assert(pp && pp0 == pp); c = page2kva(pp); for (i = 0; i < PGSIZE; i++) assert(c[i] == 0); // give free list back page_free_list = fl; // free the pages we took page_free(pp0); page_free(pp1); page_free(pp2); // number of free pages should be the same for (pp = page_free_list; pp; pp = pp->pp_link) --nfree; assert(nfree == 0); cprintf("check_page_alloc() succeeded!\n"); }
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(); time_tick(); sched_yield(); return; } // 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 == 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. switch(tf->tf_trapno) { case T_PGFLT: page_fault_handler(tf); break; case T_BRKPT: monitor(tf); break; 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); break; default: print_trapframe(tf); if (tf->tf_cs == GD_KT) { panic("unhandled trap in kernel"); } else { env_destroy(curenv); return; } } }
// check page_insert, page_remove, &c static void check_page(void) { struct PageInfo *pp, *pp0, *pp1, *pp2; struct PageInfo *fl; pte_t *ptep, *ptep1; void *va; uintptr_t mm1, mm2; int i; extern pde_t entry_pgdir[]; // should be able to allocate three pages pp0 = pp1 = pp2 = 0; assert((pp0 = page_alloc(0))); assert((pp1 = page_alloc(0))); assert((pp2 = page_alloc(0))); assert(pp0); assert(pp1 && pp1 != pp0); assert(pp2 && pp2 != pp1 && pp2 != pp0); // temporarily steal the rest of the free pages fl = page_free_list; page_free_list = 0; // should be no free memory assert(!page_alloc(0)); // there is no page allocated at address 0 assert(page_lookup(kern_pgdir, (void *) 0x0, &ptep) == NULL); // there is no free memory, so we can't allocate a page table assert(page_insert(kern_pgdir, pp1, 0x0, PTE_W) < 0); // free pp0 and try again: pp0 should be used for page table page_free(pp0); assert(page_insert(kern_pgdir, pp1, 0x0, PTE_W) == 0); assert(PTE_ADDR(kern_pgdir[0]) == page2pa(pp0)); assert(check_va2pa(kern_pgdir, 0x0) == page2pa(pp1)); assert(pp1->pp_ref == 1); assert(pp0->pp_ref == 1); // should be able to map pp2 at PGSIZE because pp0 is already allocated for page table assert(page_insert(kern_pgdir, pp2, (void*) PGSIZE, PTE_W) == 0); assert(check_va2pa(kern_pgdir, PGSIZE) == page2pa(pp2)); assert(pp2->pp_ref == 1); // should be no free memory assert(!page_alloc(0)); // should be able to map pp2 at PGSIZE because it's already there assert(page_insert(kern_pgdir, pp2, (void*) PGSIZE, PTE_W) == 0); assert(check_va2pa(kern_pgdir, PGSIZE) == page2pa(pp2)); assert(pp2->pp_ref == 1); // pp2 should NOT be on the free list // could happen in ref counts are handled sloppily in page_insert assert(!page_alloc(0)); // check that pgdir_walk returns a pointer to the pte ptep = (pte_t *) KADDR(PTE_ADDR(kern_pgdir[PDX(PGSIZE)])); assert(pgdir_walk(kern_pgdir, (void*)PGSIZE, 0) == ptep+PTX(PGSIZE)); // should be able to change permissions too. assert(page_insert(kern_pgdir, pp2, (void*) PGSIZE, PTE_W|PTE_U) == 0); assert(check_va2pa(kern_pgdir, PGSIZE) == page2pa(pp2)); assert(pp2->pp_ref == 1); assert(*pgdir_walk(kern_pgdir, (void*) PGSIZE, 0) & PTE_U); assert(kern_pgdir[0] & PTE_U); // should be able to remap with fewer permissions assert(page_insert(kern_pgdir, pp2, (void*) PGSIZE, PTE_W) == 0); assert(*pgdir_walk(kern_pgdir, (void*) PGSIZE, 0) & PTE_W); assert(!(*pgdir_walk(kern_pgdir, (void*) PGSIZE, 0) & PTE_U)); // should not be able to map at PTSIZE because need free page for page table assert(page_insert(kern_pgdir, pp0, (void*) PTSIZE, PTE_W) < 0); // insert pp1 at PGSIZE (replacing pp2) assert(page_insert(kern_pgdir, pp1, (void*) PGSIZE, PTE_W) == 0); assert(!(*pgdir_walk(kern_pgdir, (void*) PGSIZE, 0) & PTE_U)); // should have pp1 at both 0 and PGSIZE, pp2 nowhere, ... assert(check_va2pa(kern_pgdir, 0) == page2pa(pp1)); assert(check_va2pa(kern_pgdir, PGSIZE) == page2pa(pp1)); // ... and ref counts should reflect this assert(pp1->pp_ref == 2); assert(pp2->pp_ref == 0); // pp2 should be returned by page_alloc assert((pp = page_alloc(0)) && pp == pp2); // unmapping pp1 at 0 should keep pp1 at PGSIZE page_remove(kern_pgdir, 0x0); assert(check_va2pa(kern_pgdir, 0x0) == ~0); assert(check_va2pa(kern_pgdir, PGSIZE) == page2pa(pp1)); assert(pp1->pp_ref == 1); assert(pp2->pp_ref == 0); // test re-inserting pp1 at PGSIZE assert(page_insert(kern_pgdir, pp1, (void*) PGSIZE, 0) == 0); assert(pp1->pp_ref); assert(pp1->pp_link == NULL); // unmapping pp1 at PGSIZE should free it page_remove(kern_pgdir, (void*) PGSIZE); assert(check_va2pa(kern_pgdir, 0x0) == ~0); assert(check_va2pa(kern_pgdir, PGSIZE) == ~0); assert(pp1->pp_ref == 0); assert(pp2->pp_ref == 0); // so it should be returned by page_alloc assert((pp = page_alloc(0)) && pp == pp1); // should be no free memory assert(!page_alloc(0)); // forcibly take pp0 back assert(PTE_ADDR(kern_pgdir[0]) == page2pa(pp0)); kern_pgdir[0] = 0; assert(pp0->pp_ref == 1); pp0->pp_ref = 0; // check pointer arithmetic in pgdir_walk page_free(pp0); va = (void*)(PGSIZE * NPDENTRIES + PGSIZE); ptep = pgdir_walk(kern_pgdir, va, 1); ptep1 = (pte_t *) KADDR(PTE_ADDR(kern_pgdir[PDX(va)])); assert(ptep == ptep1 + PTX(va)); kern_pgdir[PDX(va)] = 0; pp0->pp_ref = 0; // check that new page tables get cleared memset(page2kva(pp0), 0xFF, PGSIZE); page_free(pp0); pgdir_walk(kern_pgdir, 0x0, 1); ptep = (pte_t *) page2kva(pp0); for(i=0; i<NPTENTRIES; i++) assert((ptep[i] & PTE_P) == 0); kern_pgdir[0] = 0; pp0->pp_ref = 0; // give free list back page_free_list = fl; // free the pages we took page_free(pp0); page_free(pp1); page_free(pp2); // test mmio_map_region mm1 = (uintptr_t) mmio_map_region(0, 4097); mm2 = (uintptr_t) mmio_map_region(0, 4096); // check that they're in the right region assert(mm1 >= MMIOBASE && mm1 + 8096 < MMIOLIM); assert(mm2 >= MMIOBASE && mm2 + 8096 < MMIOLIM); // check that they're page-aligned assert(mm1 % PGSIZE == 0 && mm2 % PGSIZE == 0); // check that they don't overlap assert(mm1 + 8096 <= mm2); // check page mappings assert(check_va2pa(kern_pgdir, mm1) == 0); assert(check_va2pa(kern_pgdir, mm1+PGSIZE) == PGSIZE); assert(check_va2pa(kern_pgdir, mm2) == 0); assert(check_va2pa(kern_pgdir, mm2+PGSIZE) == ~0); // check permissions assert(*pgdir_walk(kern_pgdir, (void*) mm1, 0) & (PTE_W|PTE_PWT|PTE_PCD)); assert(!(*pgdir_walk(kern_pgdir, (void*) mm1, 0) & PTE_U)); // clear the mappings *pgdir_walk(kern_pgdir, (void*) mm1, 0) = 0; *pgdir_walk(kern_pgdir, (void*) mm1 + PGSIZE, 0) = 0; *pgdir_walk(kern_pgdir, (void*) mm2, 0) = 0; cprintf("check_page() succeeded!\n"); }
DRESULT disk_ioctl (BYTE drive, BYTE command, void * buff){ if(drive != 0){ return RES_PARERR; } if(SDCardGetStatus() != SD_CARD_STATUS_OK){ return RES_NOTRDY; } switch(command){ case CTRL_SYNC: { if(!SDCardWaitIdle(TRUE)){ return RES_ERROR; } return RES_OK; } case GET_SECTOR_SIZE: { /* Put the block/sector length in bytes into the WORD pointed to by the void* buff pointer */ *((WORD*)buff) = SD_CARD_SECTOR_LEN; return RES_OK; } case GET_SECTOR_COUNT: { uint32 numSectors = 0; uint8 CSDRaw[16]; // Read the card Specific data register. if(!SDCardReadCSD(CSDRaw, TRUE)){ cprintf("Error Reading Card Specific Data Register\n"); return RES_ERROR; } // Process the CSD based on its type if((CSDRaw[15] & 0xC0) == 0x00){ //Version 1.0 SDCardCSDSDV1 cardData; SDCardProcessCSDSDV1(CSDRaw, &cardData); numSectors = (cardData.C_SIZE + 1) << (cardData.C_SIZE_MULT + cardData.READ_BL_LEN - 7); cprintf("Card Size: %d Sectors (Each 512 Bytes).\n", numSectors); } else if((CSDRaw[15] & 0xC0) == 0x40) { //Version 2.0 SDCardCSDSDV2 cardData; SDCardProcessCSDSDV2(CSDRaw, &cardData); numSectors = (cardData.C_SIZE + 1) << 10; cprintf("Card Size: %d Sectors (Each 512 Bytes).\n", numSectors); } else { cprintf("Error Reading Card Specific Data Register\n"); return RES_ERROR; } // Put the card size into the correct pointer location *((DWORD*) buff) = (DWORD)numSectors; return RES_OK; } case GET_BLOCK_SIZE: { /* Get erase block size in number of sectors (DWORD) */ *((DWORD*)buff) = SD_CARD_ERASE_BLOCK_LEN; break; } /* Erasing is not supported */ default: { return RES_PARERR; } } return RES_ERROR; }
void drawMainMenu(int pos) { CONSOLE_CURSOR_INFO cursor; cursor.bVisible = false; cursor.dwSize = 1; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor); int current=pos; // store the value of the currently highlighted selection gotoxy(25,4); // position on screen SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY); cprintf(" BU MicroSight "); // name of menu item SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); if (current == 1) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE); // turn text color to black // turn the text background color grey gotoxy(25,7); // position on screen cprintf("-> Alter System Variables "); // name of menu item SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); // textcolor(7); // turn the text colour back to normal // textbackground(0); // turn the text BG to black } else { gotoxy(25, 7); cprintf(" Alter System Variables "); } if(current == 2) { //SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE); // textbackground(7); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE); gotoxy(25, 9); cprintf("-> Edit Trial Details "); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); //textcolor(7); //textbackground(0); } else { gotoxy(25, 9); cprintf(" Edit Trial Details "); } if(current == 3) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE); gotoxy(25, 11); cprintf(" Set Segmentation Method "); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); } else { gotoxy(25, 11); cprintf(" Set Segmentation Method "); } if (current == 4) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE); gotoxy(25, 13); cprintf(" Begin Trial Now "); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); } else { gotoxy(25, 13); cprintf(" Begin Trial Now "); } if(current == 5) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE); gotoxy(25, 19); cprintf(" Exit "); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); } else { gotoxy(25, 19); cprintf(" Exit "); } }
void design() { int i; clrscr(); textcolor(14); /****************************** table design *********************/ gotoxy(2,2); cprintf("\xC9"); gotoxy(3,2); for(i=1; i<=74; i++) cprintf("\xCD"); gotoxy(77,2); cprintf("\xBB"); gotoxy(2,3); cprintf("\xBA"); gotoxy(2,4); cprintf("\xBA"); gotoxy(2,5); cprintf("\xBA"); gotoxy(2,6); cprintf("\xBA"); gotoxy(2,7); cprintf("\xBA"); gotoxy(2,8); cprintf("\xBA"); gotoxy(2,9); cprintf("\xBA"); gotoxy(2,10); cprintf("\xBA"); gotoxy(2,11); cprintf("\xBA"); gotoxy(2,12); cprintf("\xBA"); gotoxy(2,13); cprintf("\xBA"); gotoxy(2,14); cprintf("\xBA"); gotoxy(2,15); cprintf("\xBA"); gotoxy(2,16); cprintf("\xBA"); gotoxy(2,17); cprintf("\xBA"); gotoxy(2,18); cprintf("\xBA"); gotoxy(2,22); cprintf("\xCC"); gotoxy(2,19); cprintf("\xBA"); gotoxy(2,20); cprintf("\xBA"); gotoxy(2,21); cprintf("\xBA"); gotoxy(2,24); cprintf("\xC8"); gotoxy(2,23); cprintf("\xBA"); gotoxy(3,24); for(i=1; i<=74; i++) cprintf("\xCD"); gotoxy(77,18); cprintf("\xBA"); gotoxy(77,19); cprintf("\xBA"); gotoxy(77,20); cprintf("\xBA"); gotoxy(77,21); cprintf("\xBA"); gotoxy(77,24); cprintf("\xBC"); gotoxy(77,23); cprintf("\xBA"); gotoxy(3,22); for(i=1; i<=74; i++) cprintf("\xCD"); gotoxy(77,22); cprintf("\xB9"); //***************** gotoxy(77,3); cprintf("\xBA"); gotoxy(77,4); cprintf("\xBA"); gotoxy(77,5); cprintf("\xBA"); gotoxy(77,6); cprintf("\xBA"); gotoxy(77,7); cprintf("\xBA"); gotoxy(77,8); cprintf("\xBA"); gotoxy(77,9); cprintf("\xBA"); gotoxy(77,10); cprintf("\xBA"); gotoxy(77,11); cprintf("\xBA"); gotoxy(77,12); cprintf("\xBA"); gotoxy(77,13); cprintf("\xBA"); gotoxy(77,14); cprintf("\xBA"); gotoxy(77,15); cprintf("\xBA"); gotoxy(77,16); cprintf("\xBA"); gotoxy(77,17); cprintf("\xBA"); textcolor(RED); // }
void print_trapframe(struct trapframe *tf) { cprintf("trapframe at %p\n", tf); print_regs(&tf->tf_regs); cprintf(" ds 0x----%04x\n", tf->tf_ds); cprintf(" es 0x----%04x\n", tf->tf_es); cprintf(" fs 0x----%04x\n", tf->tf_fs); cprintf(" gs 0x----%04x\n", tf->tf_gs); cprintf(" trap 0x%08x %s\n", tf->tf_trapno, trapname(tf->tf_trapno)); cprintf(" err 0x%08x\n", tf->tf_err); cprintf(" eip 0x%08x\n", tf->tf_eip); cprintf(" cs 0x----%04x\n", tf->tf_cs); cprintf(" flag 0x%08x ", tf->tf_eflags); int i, j; for (i = 0, j = 1; i < sizeof(IA32flags) / sizeof(IA32flags[0]); i ++, j <<= 1) { if ((tf->tf_eflags & j) && IA32flags[i] != NULL) { cprintf("%s,", IA32flags[i]); } } cprintf("IOPL=%d\n", (tf->tf_eflags & FL_IOPL_MASK) >> 12); if (!trap_in_kernel(tf)) { cprintf(" esp 0x%08x\n", tf->tf_esp); cprintf(" ss 0x----%04x\n", tf->tf_ss); } }
void help() { clrscr(); design(); textcolor(WHITE); gotoxy(20,4); cprintf("\xDB\xDB\xDB\xDB\xB2 HELP ABOUT THE PROGRAM \xB2\xDB\xDB\xDB\xDB"); gotoxy(4,6); cprintf(" [ 2 ] - ENTER RECORDS : THIS OPTION ALLOWS THE USER TO ENTER NEW "); gotoxy(30,7); cprintf("RECORDS. USER ENTERS PRODUCT ID, DESCRIPTION,"); gotoxy(30,8); cprintf("QUANTITY AND UNIT PRICE. THE PROGRAMM CALCULATES"); gotoxy(30,9); cprintf("TOTAL PRICE AND DISPLAYS ON THE SCREEN."); gotoxy(4,11); cprintf(" [ 3 ] - ENTER SALES : THIS OPTION ALLOWS THE USER TO SEE PREVIOUS "); gotoxy(30,12); cprintf("SALE RECORDS."); gotoxy(4,14); cprintf(" [ 4 ] - SEARCH PURCHASE : THIS OPTION ALLOWS THE USER TO SEARCH SPECIFIC"); gotoxy(30,15); cprintf("RECORD BY ENTERING ID OR 'DESCRIPTION'"); gotoxy(4,17); cprintf(" [ 5 ] - DELETE PURCHASE : THIS OPTION ALLOWS THE USER TO DELETE A SPECIFIC"); gotoxy(30,18); cprintf("RECORD BY ENTERING ITS 'DESCRIPTION' OR ID"); gotoxy(6,23); cprintf("Press any key to continue ............."); getche(); clrscr(); design(); textcolor(WHITE); gotoxy(4,5); cprintf(" [ 6 ] - VIEW REPORT : THIS OPTION ALLOWS THE USER TO PRINT PREVIOUS"); gotoxy(30,6); cprintf("SALE RECORDS ON PRINTER"); gotoxy(4,8); cprintf(" [ 7 ] - PRINT RECORDS : THIS OPTION ALLOWS THE USER TO PRINT RECORDS"); gotoxy(30,9); cprintf("OM PRINTER."); gotoxy(4,11); cprintf(" [ 8 ] - VIEW GRAPH : THIS OPTION ALLOWS THE USER TO VIEW GRAPH "); gotoxy(30,12); cprintf("OF QUANTITY."); gotoxy(10,23); printf("Press any key to go to the MAIN MENU ........"); getche(); }
void page_fault_handler(struct Trapframe *tf) { uint64_t fault_va; // Read processor's CR2 register to find the faulting address fault_va = rcr2(); struct UTrapframe *utf; struct PageInfo *pp; // Handle kernel-mode page faults. // LAB 3: Your code here. if((tf->tf_cs & 3) == 0) { cprintf("fault_va is [%x]",fault_va); print_trapframe(tf); panic("Page fault hapened in kernel mode"); } // We've already handled kernel-mode exceptions, so if we get here, // the page fault happened in user mode. // Call the environment's page fault upcall, if one exists. Set up a // page fault stack frame on the user exception stack (below // UXSTACKTOP), then branch to curenv->env_pgfault_upcall. // // The page fault upcall might cause another page fault, in which case // we branch to the page fault upcall recursively, pushing another // page fault stack frame on top of the user exception stack. // // The trap handler needs one word of scratch space at the top of the // trap-time stack in order to return. In the non-recursive case, we // don't have to worry about this because the top of the regular user // stack is free. In the recursive case, this means we have to leave // an extra word between the current top of the exception stack and // the new stack frame because the exception stack _is_ the trap-time // stack. // // // If there's no page fault upcall, the environment didn't allocate a // page for its exception stack or can't write to it, or the exception // stack overflows, then destroy the environment that caused the fault. // Note that the grade script assumes you will first check for the page // fault upcall and print the "user fault va" message below if there is // none. The remaining three checks can be combined into a single test. // // Hints: // user_mem_assert() and env_run() are useful here. // To change what the user environment runs, modify 'curenv->env_tf' // (the 'tf' variable points at 'curenv->env_tf'). // // LAB 4: Your code here. /*check if user env has registered a pg fault upcall.*/ //cprintf("hello1"); //cprintf("hello2"); if(curenv->env_pgfault_upcall){ //user_mem_assert(curenv,(const void *)curenv->env_pgfault_upcall,8,PTE_P|PTE_U); user_mem_assert(curenv,(const void *)UXSTACKTOP-PGSIZE,PGSIZE, PTE_W | PTE_U | PTE_P); /*If user mem assert returns , then the address is valid for the env*/ if(!(tf->tf_rsp < UXSTACKTOP && tf->tf_rsp > UXSTACKTOP-PGSIZE)){ /*1st Page Fault*/ utf = (struct UTrapframe *)(UXSTACKTOP - sizeof(struct UTrapframe)); }else{ if(tf->tf_rsp - sizeof(struct UTrapframe) - 8 < (UXSTACKTOP-PGSIZE)){ env_destroy(curenv); } else { utf = (struct UTrapframe *)(tf->tf_rsp - sizeof(struct UTrapframe) - 8); } /*Nested Page Fault*/ } /*Populate the Utrapframe*/ //user_mem_assert(curenv,(const void *)utf,sizeof(struct UTrapframe),PTE_W|PTE_U); utf->utf_eflags = tf->tf_eflags; utf->utf_err = tf->tf_err; utf->utf_fault_va = fault_va; utf->utf_regs = tf->tf_regs; utf->utf_rip = tf->tf_rip; utf->utf_rsp = tf->tf_rsp; tf->tf_rip = (uint64_t)curenv->env_pgfault_upcall; tf->tf_rsp = (uint64_t)utf; env_run(curenv); }else{ // Destroy the environment that caused the fault. cprintf("[%08x] user fault va %08x ip %08x\n", curenv->env_id, fault_va, tf->tf_rip); print_trapframe(tf); env_destroy(curenv); } }
int Prins() { //CIOCNIREA if(x1==x2 && y1==y2)//daca ne-am "pupat" { //textmode(C40); _setcursortype(_NOCURSOR); gotoxy(36,20); textcolor(LIGHTBLUE+BLINK); cprintf("Ä Busted Ä"); gotoxy(37,22); textcolor(CYAN); cout.precision(1); cprintf("%f",(end-start)/CLK_TCK); getch(); exit(1); } if(x1==1) { C(1,1,80,49,"±",MAGENTA,BLUE); textbackground(BLACK); x1=2; t=RIGHT1; return 1; } if(x1==80) { C(1,1,80,49,"±",MAGENTA,BLUE); textbackground(BLACK); x1=79; t=LEFT1; return 1; } if(y1==1) { C(1,1,80,49,"±",MAGENTA,BLUE); textbackground(BLACK); y1=2; t=DOWN1; return 1; } if(y1==49) { C(1,1,80,49,"±",MAGENTA,BLUE); textbackground(BLACK); y1=48; t=UP1; return 1; } if(x2==1) { C(1,1,80,49,"±",MAGENTA,BLUE); textbackground(BLACK); x2=2; t=RIGHT2; return 1; } if(x2==80) { C(1,1,80,49,"±",MAGENTA,BLUE); textbackground(BLACK); x2=79; t=LEFT2; return 1; } if(y2==1) { C(1,1,80,49,"±",MAGENTA,BLUE); textbackground(BLACK); y2=2; t=DOWN2; return 1; } if(y2==49) { C(1,1,80,49,"±",MAGENTA,BLUE); textbackground(BLACK); y2=48; t=UP2; return 1; } return 0; }
static int _fifo_check_swap(void) { cprintf("write Virt Page c in fifo_check_swap\n"); *(unsigned char *)0x3000 = 0x0c; assert(pgfault_num==4); cprintf("write Virt Page a in fifo_check_swap\n"); *(unsigned char *)0x1000 = 0x0a; assert(pgfault_num==4); cprintf("write Virt Page d in fifo_check_swap\n"); *(unsigned char *)0x4000 = 0x0d; assert(pgfault_num==4); cprintf("write Virt Page b in fifo_check_swap\n"); *(unsigned char *)0x2000 = 0x0b; assert(pgfault_num==4); cprintf("write Virt Page e in fifo_check_swap\n"); *(unsigned char *)0x5000 = 0x0e; assert(pgfault_num==5); cprintf("write Virt Page b in fifo_check_swap\n"); *(unsigned char *)0x2000 = 0x0b; assert(pgfault_num==5); cprintf("write Virt Page a in fifo_check_swap\n"); *(unsigned char *)0x1000 = 0x0a; assert(pgfault_num==6); cprintf("write Virt Page b in fifo_check_swap\n"); *(unsigned char *)0x2000 = 0x0b; assert(pgfault_num==7); cprintf("write Virt Page c in fifo_check_swap\n"); *(unsigned char *)0x3000 = 0x0c; assert(pgfault_num==8); cprintf("write Virt Page d in fifo_check_swap\n"); *(unsigned char *)0x4000 = 0x0d; assert(pgfault_num==9); cprintf("write Virt Page e in fifo_check_swap\n"); *(unsigned char *)0x5000 = 0x0e; assert(pgfault_num==10); cprintf("write Virt Page a in fifo_check_swap\n"); assert(*(unsigned char *)0x1000 == 0x0a); *(unsigned char *)0x1000 = 0x0a; assert(pgfault_num==11); return 0; }
void Om2(int x,int y) { gotoxy(x,y); textcolor(LIGHTRED); cprintf("%c",1); }
void print_trapframe(struct Trapframe *tf) { cprintf("TRAP frame at %p from CPU %d\n", tf, cpunum()); print_regs(&tf->tf_regs); cprintf(" es 0x----%04x\n", tf->tf_es); cprintf(" ds 0x----%04x\n", tf->tf_ds); cprintf(" trap 0x%08x %s\n", tf->tf_trapno, trapname(tf->tf_trapno)); // If this trap was a page fault that just happened // (so %cr2 is meaningful), print the faulting linear address. if (tf == last_tf && tf->tf_trapno == T_PGFLT) cprintf(" cr2 0x%08x\n", rcr2()); cprintf(" err 0x%08x", tf->tf_err); // For page faults, print decoded fault error code: // U/K=fault occurred in user/kernel mode // W/R=a write/read caused the fault // PR=a protection violation caused the fault (NP=page not present). if (tf->tf_trapno == T_PGFLT) cprintf(" [%s, %s, %s]\n", tf->tf_err & 4 ? "user" : "kernel", tf->tf_err & 2 ? "write" : "read", tf->tf_err & 1 ? "protection" : "not-present"); else cprintf("\n"); cprintf(" rip 0x%08x\n", tf->tf_rip); cprintf(" cs 0x----%04x\n", tf->tf_cs); cprintf(" flag 0x%08x\n", tf->tf_eflags); if ((tf->tf_cs & 3) != 0) { cprintf(" rsp 0x%08x\n", tf->tf_rsp); cprintf(" ss 0x----%04x\n", tf->tf_ss); } }
void start_sysinit(void) { time_t tm = 0; if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); /* * network drivers */ fprintf(stderr, "load ATH Ethernet Driver\n"); system("insmod ag71xx || insmod ag7240_mod"); insmod("ledtrig-netdev"); FILE *fp = fopen("/dev/mtdblock/0", "rb"); char mac[32]; if (fp) { unsigned char buf2[256]; fseek(fp, 0x1fc00, SEEK_SET); fread(buf2, 256, 1, fp); fclose(fp); unsigned int copy[256]; int i; for (i = 0; i < 256; i++) copy[i] = buf2[i] & 0xff; sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); fprintf(stderr, "configure eth0 to %s\n", mac); MAC_SUB(mac); eval("ifconfig", "eth0", "hw", "ether", mac); MAC_ADD(mac); MAC_ADD(mac); fprintf(stderr, "configure eth1 to %s\n", mac); eval("ifconfig", "eth1", "hw", "ether", mac); #ifndef HAVE_ATH9K MAC_SUB(mac); #endif } eval("ifconfig", "eth0", "up"); eval("ifconfig", "eth1", "up"); #ifdef HAVE_SWCONFIG #ifdef HAVE_WDR2543 system("swconfig dev switch0 set reset 1"); system("swconfig dev switch0 set enable_vlan 1"); system("swconfig dev switch0 vlan 1 set ports \"1 2 3 4 9t\""); system("swconfig dev switch0 vlan 2 set ports \"0 9t\""); system("swconfig dev switch0 set apply"); eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth0", "1"); eval("vconfig", "add", "eth0", "2"); #else system("swconfig dev eth1 set reset 1"); system("swconfig dev eth1 set enable_vlan 0"); system("swconfig dev eth1 vlan 1 set ports \"0 1 2 3 4\""); system("swconfig dev eth1 set apply"); setEthLED(17, "eth0"); setSwitchLED(13, 0x2); setSwitchLED(14, 0x4); setSwitchLED(15, 0x8); setSwitchLED(16, 0x10); #endif #endif struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } detect_wireless_devices(); #ifndef HAVE_ATH9K fprintf(stderr, "configure wifi0 to %s\n", mac); eval("ifconfig", "wifi0", "hw", "ether", mac); #endif //enable wlan led (card gpio based) #if defined(HAVE_WR841v7) || defined(HAVE_WR842) || defined(HAVE_MR3420) setWirelessLedPhy0(0); #else setWirelessLedPhy0(1); #endif led_control(LED_POWER, LED_ON); led_control(LED_SES, LED_OFF); led_control(LED_SES2, LED_OFF); led_control(LED_DIAG, LED_OFF); led_control(LED_BRIDGE, LED_OFF); led_control(LED_WLAN0, LED_OFF); led_control(LED_WLAN1, LED_OFF); led_control(LED_CONNECTED, LED_OFF); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; cprintf("done\n"); }
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 2010012193 : 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 2010012193 */ /* 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 2010012193 */ /* 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. */ if (!(++ticks % TICK_NUM)) { print_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 : 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"); } }