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

C++ cprintf函数代码示例

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

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



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

示例1: print_ticks

static void print_ticks() {
    cprintf("%d ticks\n",TICK_NUM);
}
开发者ID:hotpxl,项目名称:ucore-code,代码行数:3,代码来源:trap.c


示例2: Om1

 void Om1(int x,int y)
{
	gotoxy(x,y);
	textcolor(LIGHTCYAN);
	cprintf("%c",1);
}
开发者ID:StefanTudorFlorea,项目名称:Oldies,代码行数:6,代码来源:2PLAYERS.CPP


示例3: main

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");

}
开发者ID:shiohuang,项目名称:bsp430,代码行数:71,代码来源:main.c


示例4: entry

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);

}
开发者ID:ASAP-Project,项目名称:ASAP,代码行数:80,代码来源:INVEN.C


示例5: menu

/***************************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'));
//.........这里部分代码省略.........
开发者ID:ASAP-Project,项目名称:ASAP,代码行数:101,代码来源:INVEN.C


示例6: page_fault_handler

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);
}
开发者ID:GeneralYun,项目名称:MIT-JOS-64bit-CSE506,代码行数:78,代码来源:trap.c


示例7: main

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();
}
开发者ID:h3nnn4n,项目名称:main_ccs,代码行数:81,代码来源:mhrato.c


示例8: _main

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');

}
开发者ID:MahmoudMohamedIsmail,项目名称:FOS-OS-Memory-Management,代码行数:76,代码来源:quicksort3.c


示例9: check_swap

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);
//.........这里部分代码省略.........
开发者ID:objectkuan,项目名称:ucore_pub,代码行数:101,代码来源:swap.c


示例10: trap_dispatch

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;
	}
}
开发者ID:ChenLanbo,项目名称:OS-Lab,代码行数:95,代码来源:trap.c


示例11: page_fault_handler

// 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);
}
开发者ID:ChenLanbo,项目名称:OS-Lab,代码行数:89,代码来源:trap.c


示例12: mon_backtrace

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;
}
开发者ID:joe-cai,项目名称:jos,代码行数:32,代码来源:monitor.c


示例13: _main

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++)
		{
//.........这里部分代码省略.........
开发者ID:mahmoudreda5,项目名称:OS-MM-module,代码行数:101,代码来源:tst_placement.c


示例14: serve_open

// 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;
}
开发者ID:nitin-aggarwal,项目名称:JOS,代码行数:74,代码来源:serv.c


示例15: print_regs

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);
}
开发者ID:GeneralYun,项目名称:MIT-JOS-64bit-CSE506,代码行数:19,代码来源:trap.c


示例16: check_page_alloc

//
// 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");
}
开发者ID:DoraXingyu,项目名称:JosLab_2015,代码行数:77,代码来源:pmap.c


示例17: trap_dispatch

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;
		}
	}
}
开发者ID:GeneralYun,项目名称:MIT-JOS-64bit-CSE506,代码行数:69,代码来源:trap.c


示例18: check_page

该文章已有0人参与评论

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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