Exemplo n.º 1
0
unsigned int memtest(unsigned int start ,unsigned int end)
{
    char flg486 = 0;
    unsigned int eflg, cr0, i;
    
    /* 判断CPU是386还是486及以后 */
    eflg = io_load_eflags();
    eflg |= EFLAGS_AC_BIT; /* AC-bit = 1 */
    io_store_eflags(eflg);
    eflg = io_load_eflags();
    if ((eflg & EFLAGS_AC_BIT) != 0) { /* 386‚AC = 0 */
        flg486 = 1;
    }
    eflg &= ~EFLAGS_AC_BIT;  //AC-bit = 0
    io_store_eflags(eflg);
    
    if (flg486 != 0) {
        cr0 = load_cr0();
        cr0 |= CR0_CACHE_DISABLE; /* forbid cache*/
        store_cr0(cr0);
    }
    
    i = memtest_sub(start, end);
    
    if (flg486 != 0) {
        cr0 = load_cr0();
        cr0 &= ~CR0_CACHE_DISABLE; /* allow cache*/
        store_cr0(cr0);
    }
    return i;
}
Exemplo n.º 2
0
Arquivo: memory.c Projeto: freebz/os
unsigned int memtest(unsigned int start, unsigned int end)
{
  char flg486 = 0;
  unsigned int eflg, cr0, i;

  /* 386인가, 486 이후인가의 확인 */
  eflg = io_load_eflags();
  eflg |= EFLAGS_AC_BIT;	/* AC-bit = 1 */
  io_store_eflags(eflg);
  eflg = io_load_eflags();
  if ((eflg & EFLAGS_AC_BIT) != 0) {
    /* 386에서는 AC=1로 해도 자동으로 0이 되어 버린다. */
    flg486 = 1;
  }
  eflg &= ~EFLAGS_AC_BIT;	/* AC-bit = 0 */
  io_store_eflags(eflg);

  if (flg486 != 0) {
    cr0 = load_cr0();
    cr0 |= CR0_CACHE_DISABLE;	/* 캐시 금지 */
    store_cr0(cr0);
  }

  i = memtest_sub(start, end);

  if (flg486 != 0) {
    cr0 = load_cr0();
    cr0 &= ~ CR0_CACHE_DISABLE;	/* 캐시 허가 */
    store_cr0(cr0);
  }

  return i;
}
Exemplo n.º 3
0
unsigned int memtest(unsigned int start, unsigned int end)
{
    char flg486 = 0;
    unsigned int eflg, cr0, i;
    
    eflg = io_load_eflags();
    eflg |= EFLAGS_AC_BIT; /* AC-bit = 1 */
    io_store_eflags(eflg);
    eflg = io_load_eflags();
    if((eflg & EFLAGS_AC_BIT) != 0) {
        flg486 = 1;
    }
    eflg &= ~EFLAGS_AC_BIT;
    io_store_eflags(eflg);
    
    if(flg486 != 0){
        // disable cache
        cr0 = load_cr0();
        cr0 |= CR0_CACHE_DISABLE;
        store_cr0(cr0);
    }
    i = memtest_sub(start, end);
    if (flg486 != 0) {
        // enable cache
        cr0 = load_cr0();
        cr0 &= ~CR0_CACHE_DISABLE;
        store_cr0(cr0);
    }
    return i;
}
Exemplo n.º 4
0
unsigned int memtest(unsigned int start, unsigned int end)
{
	char flg486 = 0;
	unsigned int eflg, cr0, i;

	/* 确认CPU是386还是486以上的 */
	eflg = io_load_eflags();
	eflg |= EFLAGS_AC_BIT; /* AC-bit = 1 */
	io_store_eflags(eflg);
	eflg = io_load_eflags();
	if ((eflg & EFLAGS_AC_BIT) != 0) { /* 如果是386,即使设定AC=1,AC还是会回到0 */
		flg486 = 1;
	}
	eflg &= ~EFLAGS_AC_BIT; /* AC-bit = 0 */
	io_store_eflags(eflg);

	if (flg486 != 0) {
		cr0 = load_cr0();
		cr0 |= CR0_CACHE_DISABLE; /* 禁止缓存 */
		store_cr0(cr0);
	}

	i = memtest_sub(start, end);

	if (flg486 != 0) {
		cr0 = load_cr0();
		cr0 &= ~CR0_CACHE_DISABLE; /* 允许缓存 */
		store_cr0(cr0);
	}

	return i;
}
Exemplo n.º 5
0
unsigned int memtest(unsigned int start, unsigned int end)
{
	char flg486=0;
	unsigned int eflg,cr0,i;
	//确认CPU是386还是486以上的
	eflg=io_load_eflags();
	eflg|=EFLAGS_AC_BIT;
	io_store_eflags(eflg);
	eflg=io_load_eflags();
	if((eflg&EFLAGS_AC_BIT)!=0){//如果是386,即使设定AC=1,AC的值还会自动回到0
		flg486=1;
	}
	eflg&=~EFLAGS_AC_BIT;
	io_store_eflags(eflg);
	
	if(flg486!=0){
		cr0=load_cr0();
		cr0|=CR0_CACHE_DISABLE;//禁止缓存
		store_cr0(cr0);
	}
	
	i=memtest_sub(start,end);
	
	if(flg486!=0){
		cr0=load_cr0();
		cr0&=~CR0_CACHE_DISABLE;//禁止缓存
		store_cr0(cr0);
	}
	
	return i;
}
Exemplo n.º 6
0
unsigned int memtest(unsigned int start, unsigned int end)
{
	char flg486 = 0;
	unsigned int eflg, cr0, i;

	/* 386か、486以降なのかの確認 */
	eflg = io_load_eflags();
	eflg |= EFLAGS_AC_BIT; /* AC-bit = 1 */
	io_store_eflags(eflg);
	eflg = io_load_eflags();
	if ((eflg & EFLAGS_AC_BIT) != 0) { /* 386ではAC=1にしても自動で0に戻ってしまう */
		flg486 = 1;
	}
	eflg &= ~EFLAGS_AC_BIT; /* AC-bit = 0 */
	io_store_eflags(eflg);

	if (flg486 != 0) {
		cr0 = load_cr0();
		cr0 |= CR0_CACHE_DISABLE; /* キャッシュ禁止 */
		store_cr0(cr0);
	}

	i = memtest_sub(start, end);

	if (flg486 != 0) {
		cr0 = load_cr0();
		cr0 &= ~CR0_CACHE_DISABLE; /* キャッシュ許可 */
		store_cr0(cr0);
	}

	return i;
}
Exemplo n.º 7
0
unsigned int memtest(unsigned int start,unsigned int end)
{
	char flag486 = 0;
	unsigned int eflag,cr0,i;
	//确认是386还是486
	eflag = io_load_eflags();
	eflag |= EFLAGS_AC_BIT;				//设定AC_BIT = 1,386设完后会自动归零
	io_store_eflags(eflag);
	eflag = io_load_eflags();
	if((eflag & EFLAGS_AC_BIT) != 0)	//判断AC_BIT是否为1
	{
		flag486 = 1;
	}
	eflag &= ~EFLAGS_AC_BIT;			//AC_BIT = 0
	io_store_eflags(eflag);
	
	if(flag486 != 0)
	{
		cr0 = load_cr0();
		cr0 |= CR0_CACHE_DISABLE;		//禁止缓存
		store_cr0(cr0);
	}
	
	i = memtest_sub(start,end);
	
	if(flag486 != 0)
	{
		cr0 = load_cr0();
		cr0 &= ~CR0_CACHE_DISABLE;		//启用缓存
		store_cr0(cr0);
	}
	return i;
}
Exemplo n.º 8
0
// copy from 30days_os/projects/09_day/harib06b/bootpack.c
u32 memtest(volatile u32 start, volatile u32 end)
{
  u32 memtest_sub(volatile u32 start, volatile u32 end);

	char flg486 = 0;
	u32 eflg, cr0, i;

	/* 386‚©A486ˆÈ~‚È‚Ì‚©‚ÌŠm”F */
	eflg = io_load_eflags();
	eflg |= EFLAGS_AC_BIT; /* AC-bit = 1 */
	io_store_eflags(eflg);
	eflg = io_load_eflags();
	if ((eflg & EFLAGS_AC_BIT) != 0) { /* 386‚Å‚ÍAC=1‚É‚µ‚Ä‚àŽ©“®‚Å0‚É–ß‚Á‚Ä‚µ‚Ü‚¤ */
		flg486 = 1;
	}
	eflg &= ~EFLAGS_AC_BIT; /* AC-bit = 0 */
	io_store_eflags(eflg);

	if (flg486 != 0) {
		cr0 = load_cr0();
		cr0 |= CR0_CACHE_DISABLE; /* ƒLƒƒƒbƒVƒ…‹ÖŽ~ */
		store_cr0(cr0);
	}

	i = memtest_sub(start, end);

	if (flg486 != 0) {
		cr0 = load_cr0();
		cr0 &= ~CR0_CACHE_DISABLE; /* ƒLƒƒƒbƒVƒ…‹–‰Â */
		store_cr0(cr0);
	}

	return i;
}
Exemplo n.º 9
0
/*
	memtest is used to calculate available memory, basicly it does the following:
	we first need to check if a memory unit (a byte) is valid. It's valid if 
		1) we read the value from the memroy unit
		2) we change the value to value' and write back to memroy unit
		3) we read the value from memory again, if it's value', then the memory is valid 
	Now we move to the next memory unit to check if it's valid, we keep increasing the pointer until the check fails
	then the pointer will point to the LAST availe memory, which is the size of memory available

*/
unsigned int memtest(unsigned int start, unsigned int end)
{	
	char flg486 = 0;
	unsigned int eflg, cr0, i;
	/* 
		to do the write read check, we need to disable cache, 
		because with cache in place writing to a memory might be cached 
			and reading from the same address unit might return differernt value
		Note only 486+ CPU has cache, therefore we need first check if it's 486 or lower
		if it's lower then we don't need to disable cache
	*/
	eflg = io_load_eflags();
	/* only 486+ has AC bit, that said in 386 and lower, even if we set AC to 1, it will be cleared */
	eflg |= EFLAGS_AC_BIT; 
	io_store_eflags(eflg);
	eflg = io_load_eflags();
	if((eflg & EFLAGS_AC_BIT) != 0) {
		/* if AC is NOT cleared, then it's 486 and we need to disable cache */
		flg486 = 1;
	}
	eflg &= ~EFLAGS_AC_BIT;
	io_store_eflags(eflg);

	/* disable cache by setting a bit in CR0 register */
	if(flg486) {
		cr0 = load_cr0();
		cr0 |= CR0_CACHE_DISABLE;
		store_cr0(cr0);
	}

	i = memtest_sub(start, end);

	/* re-enable cache */
	if(flg486) {
		cr0 = load_cr0();
		cr0 &= ~CR0_CACHE_DISABLE;
		store_cr0(cr0);
	}

	return i;
}
Exemplo n.º 10
0
Arquivo: memory.c Projeto: red13/chos
unsigned int memtest( unsigned int start, unsigned int end )
{
    char flg486 = 0;
    unsigned int eflg;
    unsigned int cr0;
    unsigned int i;

    /* 386か,486以降なのかを確認する */
    eflg = io_load_eflags();
    eflg |= EFLAGS_AC_BIT;
    io_store_eflags( eflg );
    eflg = io_load_eflags();
    if( ( eflg & EFLAGS_AC_BIT ) != 0 )
    {
        flg486 = 1;
    }
    eflg &= ~EFLAGS_AC_BIT;
    io_store_eflags( eflg );

    if( flg486 != 0 )
    {
        cr0 = load_cr0();
        cr0 |= CR0_CACHE_DISABLE;
        store_cr0( cr0 );
    }

    i = memtest_sub( start, end );

    if( flg486 != 0 )
    {
        cr0 = load_cr0();
        cr0 &= ~CR0_CACHE_DISABLE;
        store_cr0( cr0 );
    }

    return i;
}