示例#1
0
void 	reloca_pool(BTREE *bt, long address)
{
int	i;

   if (address == BTREE_NULL)
	i = NPAGEPOOL - 1;
   else
	i = page_of(bt, address);

   for (; i > 0; i--)
   {
	bt->pool[i] = bt->pool[i-1];
   }
}
示例#2
0
bool Flasher_::flash_aligned(const Data *address, const Data *bufp,
                             size_t buflen) {

  R2P_ASSERT(is_aligned(address));
  R2P_ASSERT(is_aligned(bufp));
  R2P_ASSERT(is_aligned(reinterpret_cast<const void *>(buflen)));

  bool writeback = false;

  // Process all given words
  while (buflen > 0) {
    PageID old_page = page;
    page = page_of(reinterpret_cast<const uint8_t *>(address));
    ptrdiff_t offset = reinterpret_cast<ptrdiff_t>(address) -
                       reinterpret_cast<ptrdiff_t>(address_of(page));
    size_t length = (PAGE_SIZE - offset);

    // Read back new page if page has changed
    if (old_page != page) {
      if (page_modified) {
        if (!write_if_needed(old_page, page_bufp)) return false;
      }
      if (!read(page, page_bufp)) return false;
      page_modified = false;
    }

    // Process no more bytes than remaining
    if (length > buflen) {
      length = buflen;
    } else {
      writeback = true;
    }

    // Copy buffer into page buffer and mark as tainted
    memcpy(&page_bufp[offset / WORD_ALIGNMENT], bufp, length);
    page_modified = true;
    buflen -= length;

    // Writeback buffer if needed
    if (writeback) {
      if (!write_if_needed(page, page_bufp)) return false;
      writeback = false;
    }
  }
  return true;
}
示例#3
0
size_t inventory_column::page_of( const inventory_entry &entry ) const {
    return page_of( std::distance( entries.begin(), std::find( entries.begin(), entries.end(), entry ) ) );
}
示例#4
0
bool inventory_column::is_selected_by_category( const inventory_entry &entry ) const
{
    return entry.is_item() && mode == navigation_mode::CATEGORY
                           && entry.get_category_ptr() == get_selected().get_category_ptr()
                           && page_of( entry ) == page_index();
}
 size_t pages_count() const {
     return page_of( entries.size() + entries_per_page - 1 );
 }
 size_t page_index() const {
     return page_of( page_offset );
 }
示例#7
0
文件: newmt.c 项目: kisom/pmon
static int newmt(void)
{
	int i = 0, j = 0;
	unsigned long chunks;
	unsigned long lo, hi;


#if NMOD_FRAMEBUFFER > 0 
	video_cls();
#endif
	if(setjmp(jmpb_mt)&&(returncode==2)){
		ioctl (STDIN, TCSETAF, &sav);
		firsttime = 0;
		v->test = 0;
		v->pass = 0;
		v->msg_line = 0;
		v->ecount = 0;
		v->ecc_ecount = 0;
		autotest=0;
		firsttime=0;
		/* Clear the screen */
#if NMOD_FRAMEBUFFER > 0
		video_cls();
#endif
		return 0;
	}

	ioctl (STDIN, CBREAK, &sav);
	while(1)
	{
		window=0;
		/* If first time, initialize test */
		windows[0].start =LOW_TEST_ADR>>12;
		windows[0].end= HIGH_TEST_ADR>>12;
        
		if(!firsttime){init();firsttime++;}
        
	    bail = 0;

		/* Find the memory areas I am going to test */
		compute_segments(window);

		if (segs == 0) {
			goto skip_window;
		}
		/* Now map in the window... */
		if (map_page(v->map[0].pbase_addr) < 0) {
			goto skip_window;
		}

		/* Update display of memory segments being tested */
		lo = page_of(v->map[0].start);
		hi = page_of(v->map[segs -1].end);
		aprint(LINE_RANGE, COL_MID+9, lo-0x80000);
		cprint(LINE_RANGE, COL_MID+14, " - ");
		aprint(LINE_RANGE, COL_MID+17, hi-0x80000);
		aprint(LINE_RANGE, COL_MID+23, v->selected_pages);
		cprint(LINE_RANGE, COL_MID+28, 
				((ulong)&_start == LOW_TEST_ADR)?"          ":" Relocated");

		/* Now setup the test parameters based on the current test number */
		/* Figure out the next test to run */
		if (v->testsel >= 0) {
			v->test = v->testsel;
		}
		dprint(LINE_TST, COL_MID+6, v->test, 2, 1);
		cprint(LINE_TST, COL_MID+9, tseq[v->test].msg);
		set_cache(tseq[v->test].cache);

		/* Compute the number of SPINSZ memory segments */
		chunks = 0;
		for(i = 0; i < segs; i++) {
			unsigned long len;
			len = v->map[i].end - v->map[i].start;
			chunks += (len + SPINSZ -1)/SPINSZ;
		}
        
		test_ticks = find_ticks_for_test(chunks, v->test);
        nticks = 0;
		v->tptr = 0;
		cprint(1, COL_MID+8, "                                         ");
		switch(tseq[v->test].pat) {
			/* Now do the testing according to the selected pattern */
			case 0:	/* Moving inversions, all ones and zeros */
				p1 = 0;
				p2 = ~p1;
				movinv1(tseq[v->test].iter,p1,p2);
				BAILOUT;

				/* Switch patterns */
				p2 = p1;
				p1 = ~p2;
				movinv1(tseq[v->test].iter,p1,p2);
				BAILOUT;
				break;

			case 1: /* Moving inversions, 8 bit wide walking ones and zeros. */
                p0 = 0x80;
				for (i=0; i<8; i++, p0=p0>>1) {
					p1 = p0 | (p0<<8) | (p0<<16) | (p0<<24);
					p2 = ~p1;
					movinv1(tseq[v->test].iter,p1,p2);
					BAILOUT;

					/* Switch patterns */
					p2 = p1;
					p1 = ~p2;
					movinv1(tseq[v->test].iter,p1,p2);
					BAILOUT
				}
				break;

			case 2: /* Moving inversions, 32 bit shifting pattern, very long */
                {
                    u_int32_t pa = 0;
                    for (i=0, pa=1; pa; pa=pa<<1, i++) {
					    movinv32(tseq[v->test].iter,pa, 1, 0x80000000, 0, i);
					    BAILOUT
                        movinv32(tseq[v->test].iter,~pa, 0xfffffffe,
								0x7fffffff, 1, i);
					    BAILOUT
				    }
                }
				break;

			case 3: /* Modulo X check, all ones and zeros */
                p1=0;
				for (i=0; i<MOD_SZ; i++) {
					p2 = ~p1;
					modtst(i, tseq[v->test].iter, p1, p2);
					BAILOUT

					/* Switch patterns */
					p2 = p1;
					p1 = ~p2;
					modtst(i, tseq[v->test].iter, p1,p2);
					BAILOUT
				}
				break;

			case 4: /* Modulo X check, 8 bit pattern */
                p0 = 0x80;
				for (j=0; j<8; j++, p0=p0>>1) {
					p1 = p0 | (p0<<8) | (p0<<16) | (p0<<24);
					for (i=0; i<MOD_SZ; i++) {
						p2 = ~p1;
						modtst(i, tseq[v->test].iter, p1, p2);
						BAILOUT

						/* Switch patterns */
						p2 = p1;
						p1 = ~p2;
						modtst(i, tseq[v->test].iter, p1, p2);
						BAILOUT
					}
				}
				break;
			case 5: /* Address test, walking ones */
                addr_tst1();
				BAILOUT;
				break;

			case 6: /* Address test, own address */
                addr_tst2();
				BAILOUT;
				break;

			case 7: /* Block move test */
                block_move(tseq[v->test].iter);
				BAILOUT;
				break;
			case 8: /* Bit fade test */
                if (window == 0 ) {
					bit_fade();
				}
				BAILOUT;
				break;
			case 9: /* Random Data Sequence */
                for (i=0; i < tseq[v->test].iter; i++) {
					movinvr();
					BAILOUT;
				}
				break;
			case 10: /* Random Data */
                for (i=0; i < tseq[v->test].iter; i++) {
					p1 = rand();
					p2 = ~p1;
					movinv1(2,p1,p2);
					BAILOUT;
				}
				break;
		}
skip_window:
		if (bail) {
			goto bail_test;
		}
		/* Rever to the default mapping and enable the cache */
		paging_off();
		set_cache(1);
		window++;
		if (window >= sizeof(windows)/sizeof(windows[0])) {
			window = 0;
		}
		/* We finished the test so clear the pattern */
		cprint(LINE_PAT, COL_PAT, "            ");
skip_test:
		v->test++;
bail_test:

		paging_off();
		set_cache(1);
		check_input();
		window = 0;
		cprint(LINE_PAT, COL_PAT-3, "   ");
		/* If this was the last test then we finished a pass */
		if (v->test >= DEFTESTS || v->testsel >= 0) {
			v->pass++;
			dprint(LINE_INFO, COL_PASS, v->pass, 5, 0);
			v->test = 0;
			v->total_ticks = 0;
			v->pptr = 0;
			cprint(0, COL_MID+8,
				"                                         ");
		}
	}
	return 0;
}