Ejemplo n.º 1
0
// set vpn to PAGE_MAP
static void set_vpn(UINT32 const lpn, UINT32 const vpn)
{
	set_v++;

	UINT32 index;
	for(index = 0; index < CMT_SIZE; index++)
	{
		if(cmt[index].lpn == lpn)
		{
			cmt_w_hit++;
			goto WRITE_CACHE_ENTRY;
		}
	}
	/*
	 * not in CMT
	 */
	evict_mapping();

	index = cmt_hand;
	cmt_hand = (cmt_hand + 1) % CMT_SIZE;
	cmt[index].lpn = lpn;

	WRITE_CACHE_ENTRY:

	cmt[index].vpn = SET_DIRTY(vpn);
	cmt[index].sc = TRUE;
	return;
}
Ejemplo n.º 2
0
/*
 * Add an inverse entry for the physical page associated with mapping from vaddr 
 * to paddr into the coremap. Inverse mapping means the page is indexed by page
 * number calculated using paddr.
 */
int add_ppage (u_int32_t vaddr, u_int32_t paddr, pid_t pid, u_int32_t status)
{
    int result = 0;
    
    int spl=splhigh();    
    paddr = paddr & PAGE_FRAME;
    
    //get the index of the page in the page table
    int page_index = (paddr - coremap_base) / PAGE_SIZE;
    //make sure that the paddr address is valid
    assert( (coremap[ page_index ].paddr & PAGE_FRAME) == paddr );
    
    /*
     * Add the mapping and set the attribute bits
     */
    coremap[ page_index ].vaddr = vaddr;
    //If it is a kernel address allocated by kernel then set kernel attribute flag
    if(vaddr > USERTOP)
        coremap[ page_index ].paddr = SET_VALID(paddr)|SET_DIRTY(paddr)|SET_KERNEL(paddr);
    else
        coremap[ page_index ].paddr = SET_VALID(paddr)|SET_DIRTY(paddr);
    
    /*Initialize _PTE fields for this entry*/
    coremap[ page_index ].last_access_time_sec = 0;
    coremap[ page_index ].last_access_time_nsec = 0;
    coremap[ page_index ].pid = pid;
    coremap[ page_index ].status = PAGE_DIRTY;
    
    /*
     * mark (unavailable) the page entry of coremap.
     */
    if(!bitmap_isset(core_memmap,page_index))
        bitmap_mark(core_memmap, page_index);    
    splx(spl);
        
    return result;
}
Ejemplo n.º 3
0
FBCALL void fb_GfxEllipse(void *target, float fx, float fy, float radius, unsigned int color, float aspect, float start, float end, int fill, int flags)
{
	FB_GFXCTX *context;
	int x, y, x1, y1, top, bottom;
	unsigned int orig_color;
	float a, b, orig_x, orig_y, increment;

	FB_GRAPHICS_LOCK( );

	if (!__fb_gfx || radius <= 0.0) {
		FB_GRAPHICS_UNLOCK( );
		return;
	}

	context = fb_hGetContext();
	orig_x = fx;
	orig_y = fy;

	fb_hPrepareTarget(context, target);

	orig_color = color;
	if (flags & DEFAULT_COLOR_1)
		color = context->fg_color;
	else
		color = fb_hFixColor(context->target_bpp, color);
	
	fb_hSetPixelTransfer(context, color);

	fb_hFixRelative(context, flags, &fx, &fy, NULL, NULL);

	fb_hTranslateCoord(context, fx, fy, &x, &y);

	if (context->flags & CTX_WINDOW_ACTIVE) {
		/* radius gets multiplied by the VIEW/WINDOW width ratio (aspect is unchanged) */
		radius *= (context->view_w / context->win_w);
	}

	if (aspect == 0.0)
		aspect = __fb_gfx->aspect;

	if (aspect > 1.0) {
		a = (radius / aspect);
		b = radius;
	} else {
		a = radius;
		b = (radius * aspect);
	}

	if ((start != 0.0) || (end != 3.141593f * 2.0)) {
		if (start < 0) {
			start = -start;
			get_arc_point(start, a, b, &x1, &y1);
			x1 = orig_x + x1;
			y1 = orig_y - y1;
			fb_GfxLine(target, orig_x, orig_y, x1, y1, orig_color, LINE_TYPE_LINE, 0xFFFF, COORD_TYPE_AA | (flags & ~COORD_TYPE_MASK));
		}
		if (end < 0) {
			end = -end;
			get_arc_point(end, a, b, &x1, &y1);
			x1 = orig_x + x1;
			y1 = orig_y - y1;
			fb_GfxLine(target, orig_x, orig_y, x1, y1, orig_color, LINE_TYPE_LINE, 0xFFFF, COORD_TYPE_AA | (flags & ~COORD_TYPE_MASK));
		}
		
		while (end < start)
			end += 2 * PI;
		while (end - start > 2 * PI)
			start += 2 * PI;

		increment = 1 / (sqrt(a) * sqrt(b) * 1.5);

		DRIVER_LOCK();

		top = bottom = y;
		for (; start < end + (increment / 2); start += increment) {
			get_arc_point(start, a, b, &x1, &y1);
			x1 = x + x1;
			y1 = y - y1;
			if ((x1 < context->view_x) || (x1 >= context->view_x + context->view_w) ||
			    (y1 < context->view_y) || (y1 >= context->view_y + context->view_h))
				continue;
			context->put_pixel(context, x1, y1, color);
			if (y1 > bottom)
				bottom = y1;
			if (y1 < top)
				top = y1;
		}
	} else {
		DRIVER_LOCK();
		draw_ellipse(context, x, y, a, b, color, fill, &top, &bottom);
	}

	top = MID(context->view_y, top, context->view_y + context->view_h - 1);
	bottom = MID(context->view_y, bottom, context->view_y + context->view_h - 1);
	if( top > bottom )
		SWAP( top, bottom );

	SET_DIRTY(context, top, bottom - top + 1);

	DRIVER_UNLOCK();
	FB_GRAPHICS_UNLOCK( );
}
Ejemplo n.º 4
0
int getClockFrame(int notme)
{
    int frame;

    // iterate through rpts (0x2400 - LC3_RPT_END)
    int maxWrap = 20;
    for (;maxWrap; cBigHand += 2, cLittleHand = 0) {
        int i;
        int rpte1;
        int upta, upte1;

        if (cBigHand >= LC3_RPT_END) {
            DEBUG_STATEMENT(DEBUG_MMU,"\nClock is wrapping");
            cBigHand = LC3_RPT;
            maxWrap--;
        }

        rpte1 = memory[cBigHand];

        if (DEFINED(rpte1) && REFERENCED(rpte1)) {
            // clear reference
            DEBUG_STATEMENT(DEBUG_MMU,"\nclearing ref for rpte");
            memory[cBigHand] = rpte1 = CLEAR_REF(rpte1);
        } else if (DEFINED(rpte1)) { // if one is non-referenced go to the user page table
            // scout out the upt!! note that this has not been referenced
            if (DEBUG_MMU) { outPTE("\nRPT entry being checked - ", cBigHand); }
            upta = (FRAME(rpte1)<<6);

            for (i = cLittleHand % 64; i < 64;i += 2, cLittleHand = i % 64) { // - iterate over userpage table
                upte1 = memory[upta + (i)];
                if (PINNED(upte1) || FRAME(upte1) == notme) {
                    DEBUG_STATEMENT(DEBUG_MMU,"\nupte1 frame was the notme frame (%x = %x) or pinned", FRAME(upte1), notme);
                    if (DEBUG_MMU) { outPTE("UPT entry being checked - ", upta + i); }

                    continue;
                }

                if (DEFINED(upte1) && REFERENCED(upte1)) { // - if entry is referenced un-reference and move on
                    // clear reference
                    DEBUG_STATEMENT(DEBUG_MMU,"\nclearing ref for upte %d", cLittleHand);
                    memory[cBigHand] = rpte1 = SET_PINNED(rpte1);
                    memory[upta + (i)] = upte1 = CLEAR_REF(upte1);
                } else if (DEFINED(upte1)) { // - otherwise prep it for being put into swap
                    // we can use the frame referenced by upte1
                    if (DEBUG_MMU) { outPTE("UPT entry being checked - ", upta + 1); }
                    DEBUG_STATEMENT(DEBUG_MMU,"\nUpte1 %x, Upte2 %x", upte1, memory[upta + (i + 1)]);
                    memory[cBigHand] = rpte1 = SET_DIRTY(rpte1);
                    frame = FRAME(upte1);
                    swapOutFrame(upta + i);
                    cLittleHand += 2;
                    DEBUG_STATEMENT(DEBUG_MMU,"\nFound a data frame that can be used! (%d, %x)", frame, frame);

                    return frame;
                }
            }

            cLittleHand = 0;
            if (!REFERENCED(rpte1) && !PINNED(rpte1) && FRAME(rpte1) != notme) { // if we only replaced or did nothing to upte entries
                // we can use the frame referenced by rpte1
                frame = FRAME(rpte1);

                DEBUG_STATEMENT(DEBUG_MMU,"\nFound a upt frame that can be used! (%d, %x)", frame, frame);
                swapOutFrame(cBigHand);
                cBigHand += 2;
                return frame;
            } else { // otherwise remove the pin flag
                memory[cBigHand] = rpte1 = CLEAR_PINNED(rpte1);
            }

        }
    } // when you get the bottom start at the top again

    DEBUG_STATEMENT(DEBUG_MMU,"\n No valid frame found notme = %d", notme);
    if (DEBUG_MMU) {  displayTableHierarchy(); }

    return -1;
}
Ejemplo n.º 5
0
unsigned short int *getMemAdr(int va, int rwFlg)
{
	unsigned short int pa;
	int rpta, rpte1, rpte2;
	int upta, upte1, upte2;
	int rptFrame, uptFrame;
    memAccess += 2;

//	rpta = 0x2400 + RPTI(va);
    rpta = tcb[curTask].RPT + RPTI(va);
	rpte1 = memory[rpta];
	rpte2 = memory[rpta+1];

	// turn off virtual addressing for system RAM
	if (va < 0x3000) return &memory[va];
#if MMU_ENABLE
	if (DEFINED(rpte1))
	{
//        printf("\nUPT frame already defined");
		// defined
        memHits++;
	}
	else
	{
		// fault
        memPageFaults++;
		rptFrame = getFrame(-1);
		rpte1 = SET_DEFINED(rptFrame);
		if (PAGED(rpte2))
		{
            //upt is in swap and we need to read it back in
			accessPage(SWAPPAGE(rpte2), rptFrame, PAGE_READ);
		}
		else
		{
            //initialize the upt memory
            memset(&memory[(rptFrame<<6)], 0, 128);
		}
	}


	memory[rpta] = rpte1 = SET_REF(rpte1);
	memory[rpta+1] = rpte2;

	upta = (FRAME(rpte1)<<6) + UPTI(va);
	upte1 = memory[upta];
	upte2 = memory[upta+1];

	if (DEFINED(upte1))
	{
		// defined
        memHits++;
	}
	else
	{
		// fault
        memPageFaults++;
		uptFrame = getFrame(FRAME(memory[rpta]));
        memory[rpta] = rpte1 = SET_REF(SET_DIRTY(rpte1));
        upte1 = SET_DEFINED(uptFrame);

        if (PAGED(upte2))
		{
            //get the data frame from swap
			accessPage(SWAPPAGE(upte2), uptFrame, PAGE_READ);
		}
		else
		{
            //we don't need to do anything
            //but we could initialize the mem to 0xf025 which is lc-3 halt instruction
            memset(&memory[(uptFrame<<6)], 0xf025, 128);
		}
	}

    if (rwFlg) {
        upte1 = SET_DIRTY(upte1);
    }

    memory[upta] = SET_REF(upte1);
	memory[upta+1] = upte2;

	return &memory[(FRAME(upte1)<<6) + FRAMEOFFSET(va)];
#else
	return &memory[va];
#endif
} // end getMemAdr
Ejemplo n.º 6
0
unsigned short int *getMemAdr(int va, int rwFlg)
{
	unsigned short int pa;
	int rpta, rpte1, rpte2;
	int upta, upte1, upte2;
	int rptFrame, uptFrame;


	rpta = tcb[curTask].RPT + RPTI(va);
	rpte1 = memory[rpta];
	rpte2 = memory[rpta+1];

	// turn off virtual addressing for system RAM
	if (va < 0x3000) return &memory[va];


#if MMU_ENABLE
	if (DEFINED(rpte1))
	{
		memHits++;
	}
	else
	{
		// fault
		memPageFaults++;
		rptFrame = getFrame(-1);
		assert(rptFrame >= 192);
		rpte1 = SET_DEFINED(rptFrame);
		if (PAGED(rpte2))
		{
			accessPage(SWAPPAGE(rpte2), rptFrame, PAGE_READ);
			pageReads++;
		}
		else
		{
			rpte1 = SET_DIRTY(rpte1); rpte2 = 0;
			memset(&memory[(rptFrame<<6)], 0, 128);
		}
	}


	memory[rpta] = rpte1 = SET_REF(rpte1);
	memory[rpta+1] = rpte2;

	upta = (FRAME(rpte1)<<6) + UPTI(va);
	upte1 = memory[upta];
	upte2 = memory[upta+1];

	if (DEFINED(upte1))
	{
		memHits++;
	}
	else
	{
		// fault
		memPageFaults++;
		uptFrame = getFrame(FRAME(memory[rpta]));
		assert(uptFrame >= 192);
		upte1 = SET_DEFINED(uptFrame);
		if (PAGED(upte2))
		{
			accessPage(SWAPPAGE(upte2), uptFrame, PAGE_READ);
			pageReads++;
		}
		else
		{
			upte1 = SET_DIRTY(upte1); upte2 = 0;
		}
	}

	if(rwFlg != 0){
		upte1 = SET_DIRTY(upte1);
	}

	memory[upta] = SET_REF(upte1);
	memory[upta+1] = upte2;

	memAccess = memHits + memPageFaults;
	return &memory[(FRAME(upte1)<<6) + FRAMEOFFSET(va)];
#else
	pa = va;
#endif
	return &memory[pa];
} // end getMemAdr
Ejemplo n.º 7
0
unsigned short int *getMemAdr(int va, int rwFlg)
{
	unsigned short int pa;
	int rpta, rpte1, rpte2;
	int upta, upte1, upte2;
	int rptFrame, uptFrame;
	extern TCB tcb[MAX_TASKS];
	extern int curTask;

	//stat
	memAccess++;

	rpta = tcb[curTask].RPT + RPTI(va);	// 0x2400 + RPTI(va);
	rpte1 = memory[rpta];
	rpte2 = memory[rpta+1];

	// turn off virtual addressing for system RAM
	if (va < 0x3000) return &memory[va];
#if MMU_ENABLE
	if (DEFINED(rpte1))
	{
		// defined
		//stat
		memHits++;
		if (rwFlg)
			rpte1 = SET_DIRTY(rpte1);
	}
	else
	{
		// fault
		//stat
		memPageFaults++;

		rptFrame = getFrame(-1);
		rpte1 = SET_DEFINED(rptFrame);
		if (PAGED(rpte2))
		{
			accessPage(SWAPPAGE(rpte2), rptFrame, PAGE_READ);
			//stat
			pageReads++;
			//clean
			if (rwFlg)
				rpte1 = SET_DIRTY(rpte1);
			else
				rpte1 = CLEAR_DIRTY(rpte1);
		}
		else
		{
			memset(&memory[(rptFrame<<6)], 0, 128);
			//dirty
			rpte1 = SET_DIRTY(rpte1);
		}
	}

	
	rpte1 = SET_PINNED(rpte1);
	memory[rpta] = rpte1 = SET_REF(rpte1);
	memory[rpta+1] = rpte2;

	upta = (FRAME(rpte1)<<6) + UPTI(va);
	upte1 = memory[upta];
	upte2 = memory[upta+1];

	//stat
	memAccess++;

	if (DEFINED(upte1))
	{
		// defined
		//stat
		memHits++;
		if (rwFlg)
			upte1 = SET_DIRTY(upte1);
	}
	else
	{
		// fault
		//stat
		memPageFaults++;

		uptFrame = getFrame(FRAME(memory[rpta]));
		upte1 = SET_DEFINED(uptFrame);
		if (PAGED(upte2))
		{
			accessPage(SWAPPAGE(upte2), uptFrame, PAGE_READ);
			//stat
			pageReads++;
			//clean unless being written to
			if (rwFlg)
				upte1 = SET_DIRTY(upte1);
			else
				upte1 = CLEAR_DIRTY(upte1);
		}
		else
		{
			//dirty
			upte1 = SET_DIRTY(upte1);
		}
	}

	rpte1 = SET_PINNED(rpte1);
	memory[rpta] = rpte1;
	memory[upta] = upte1 = SET_REF(upte1);
	memory[upta+1] = upte2;


	return &memory[(FRAME(upte1)<<6) + FRAMEOFFSET(va)];
#else
	return &memory[va];
#endif
} // end getMemAdr
Ejemplo n.º 8
0
void fb_GfxPrintBufferEx( const void *buffer, size_t len, int mask )
{
	FB_GFXCTX *context;
    const char *pachText = (const char *) buffer;
    int win_left, win_top, win_cols, win_rows;
    int view_top, view_bottom;
    fb_PrintInfo info;
    fb_ConHooks hooks;

	FB_GRAPHICS_LOCK( );

    /* Do we want to correct the console cursor position? */
    if( (mask & FB_PRINT_FORCE_ADJUST)==0 ) {
        /* No, we can check for the length to avoid unnecessary stuff ... */
        if( len==0 ) {
            FB_GRAPHICS_UNLOCK( );
            return;
        }
    }

	context = fb_hGetContext( );
	fb_hPrepareTarget(context, NULL);
	fb_hSetPixelTransfer(context, MASK_A_32);

	DRIVER_LOCK();

    fb_GetSize( &win_cols, &win_rows );
    fb_ConsoleGetView( &view_top, &view_bottom );
    win_left = win_top = 0;

    hooks.Opaque        = &info;
    hooks.Scroll        = fb_hHookConScroll;
    hooks.Write         = fb_hHookConWrite;
    hooks.Border.Left   = win_left;
    hooks.Border.Top    = win_top + view_top - 1;
    hooks.Border.Right  = win_left + win_cols - 1;
    hooks.Border.Bottom = win_top + view_bottom - 1;

	info.context = context;
    info.dirty_start = info.dirty_end = 0;

    {
        hooks.Coord.X = __fb_gfx->cursor_x;
        hooks.Coord.Y = __fb_gfx->cursor_y;

        if( __fb_gfx->flags & PRINT_SCROLL_WAS_OFF ) {
            __fb_gfx->flags &= ~PRINT_SCROLL_WAS_OFF;
            ++hooks.Coord.Y;
            hooks.Coord.X = hooks.Border.Left;
            fb_hConCheckScroll( &hooks );
        }

        fb_ConPrintTTY( &hooks,
                        pachText,
                        len,
                        TRUE );

        if( hooks.Coord.X != hooks.Border.Left
            || hooks.Coord.Y != (hooks.Border.Bottom+1) )
        {
            fb_hConCheckScroll( &hooks );
        } else {
            __fb_gfx->flags |= PRINT_SCROLL_WAS_OFF;
            hooks.Coord.X = hooks.Border.Right;
            hooks.Coord.Y = hooks.Border.Bottom;
        }
        fb_GfxLocateRaw( hooks.Coord.Y, hooks.Coord.X, -1 );
    }

    SET_DIRTY(context, info.dirty_start, info.dirty_end - info.dirty_start);

    DRIVER_UNLOCK();
	FB_GRAPHICS_UNLOCK( );
}
Ejemplo n.º 9
0
int getFrame(int notme)
{
	int frame;
	frame = getAvailableFrame();
	if (frame >=0) return frame;

	// run clock
	int i, j, upta, frameToRemove;
	i = lastRpte;
	// i = 0x2400;
	// j = lastUpte;
	while(1){
		// for(i=0x2400;i<0x3000;i+=2){
			// printf("%x", i);
			if(DEFINED(memory[i])){

				upta = FRAME(memory[i]);
				upta = (upta<<6);

				//double confirm
				int k;
				bool nothingInFrame = 1;
				for(k=upta;k<upta+64;k+=2){
					if(DEFINED(memory[k])){
						nothingInFrame = 0;
						break;
					}
				}

				if(nothingInFrame && FRAME(memory[i])!=notme){
					frameToRemove = FRAME(memory[i]);
					lastRpte=i+2;
					memory[i] = CLEAR_DEFINED(memory[i]);
					memory[i] = CLEAR_REF(memory[i]);

					if(PAGED(memory[i+1]) && DIRTY(memory[i])){
						memory[i+1] = accessPage(SWAPPAGE(memory[i+1]), frameToRemove, PAGE_OLD_WRITE);
					}else{
						memory[i+1] = accessPage(0, frameToRemove, PAGE_NEW_WRITE);
					}
					memory[i+1] = SET_PAGED(memory[i+1]);
					memory[i] = SET_DIRTY(memory[i]);
					//possibly clear frame number
					return frameToRemove;
					// i can swap out this upt
				}

				// for(j=upta;j<upta+64;j+=2){
				while(uptOffset < 64){
					j = upta + uptOffset;
				
					if(DEFINED(memory[j])){
						if(REFERENCED(memory[j])){
							memory[j] = CLEAR_REF(memory[j]);
						}else{
							//use this data frame
							frameToRemove = FRAME(memory[j]);
							lastRpte = i;
							memory[j] = CLEAR_DEFINED(memory[j]);
							memory[j] = CLEAR_REF(memory[j]);
							// memory[j] = SWAPPAGE(memory[j]);
							if(PAGED(memory[j+1]) && DIRTY(memory[j])){
								memory[j+1] = accessPage(SWAPPAGE(memory[j+1]), frameToRemove, PAGE_OLD_WRITE);
							}else{
								memory[j+1] = accessPage(0, frameToRemove, PAGE_NEW_WRITE);
							}
							memory[j+1] = SET_PAGED(memory[j+1]);
							uptOffset+=2; // may not need this line
							//need to loop through rest next time but if nothing dont remove this one
							return frameToRemove;
						}
					}

					uptOffset+=2;
				}
				uptOffset = 0;
				// }
			}
		i+=2;
		if(i==0x3000){
			i=0x2400;
		}
		// }
	}

	// memory[(frameToRemove<<6)] 
	return frame;
}
Ejemplo n.º 10
0
unsigned short int *getMemAdr(int va, int rwFlg)
{
	unsigned short int pa;
	int rpta, rpte1, rpte2;
	int upta, upte1, upte2;
	int rptFrame, uptFrame;

	rpta = 0x2400 + RPTI(va) + 0x40*curTask; // address of the root page table
	rpte1 = memory[rpta];		// get a word
	rpte2 = memory[rpta+1];		// get another word

	// turn off virtual addressing for system RAM
	if (va < 0x3000) return &memory[va];
#if MMU_ENABLE

	// printf("using memory Management\n");

	if (DEFINED(rpte1))
	{
		memHits++;
		// defined
	}
	else
	{
		memPageFaults++;
		// fault
		rptFrame = getFrame(-1);
		rpte1 = SET_DEFINED(rptFrame); // setting the frame bit in the user page table
		rpte1 = SET_DIRTY(rpte1);
		if (PAGED(rpte2)) // it exists in swap space
		{
			accessPage(SWAPPAGE(rpte2), rptFrame, PAGE_READ);
		}
		else
		{
			memset(&memory[(rptFrame<<6)], 0, 128); //sets 128 bytes to 0 why is it 128? why bitshift by 6?
		}
	}


	memory[rpta] = rpte1 = SET_REF(rpte1); // sets the referenced bit in the root page table
	memory[rpta+1] = rpte2;

	upta = (FRAME(rpte1)<<6) + UPTI(va);
	upte1 = memory[upta];
	upte2 = memory[upta+1];

	if (DEFINED(upte1))
	{
		memHits++;
		// defined
	}
	else
	{
		memPageFaults++;
		// fault
		uptFrame = getFrame(FRAME(memory[rpta]));
		upte1 = SET_DEFINED(uptFrame);
		upte1 = SET_DIRTY(upte1);
		if (PAGED(upte2))
		{
			accessPage(SWAPPAGE(upte2), uptFrame, PAGE_READ);
		}
		else
		{
			memset(&memory[(uptFrame<<6)], 0, 128); //sets 128 bytes to 0 why is it 128? why bitshift by 6?
		}
	}

	if(rwFlg){
		memory[rpta] = SET_DIRTY(memory[rpta]);
	}else{

	}

	memory[upta] = SET_REF(upte1);
	memory[upta+1] = upte2;

	return &memory[(FRAME(upte1)<<6) + FRAMEOFFSET(va)];
#else
	return &memory[va];
#endif
} // end getMemAdr