Example #1
0
void timer_settime(timer_t* timer, unsigned int timeout)
{
    timer->timeout = timeout + timerctl.count;
    timer->flags = TIMER_FLAGS_USING;
    int e = io_load_eflags();
    io_cli();
    timer_t *t = timerctl.t0, *s;
    if (timer->timeout <= t->timeout) {
        /* 插入前面 */
        timerctl.t0 = timer;
        timer->next = t; /* 下个是t */
        timerctl.next = timer->timeout;
        io_store_eflags(e);
        return;
    }
    /* 寻找插入位置 */
    for (;;) {
        s = t;
        t = t->next;
        if (timer->timeout <= t->timeout) {
            /* 插入s和t之间 */
            s->next = timer; /* s下个是timer */
            timer->next = t; /* timer下个是t */
            io_store_eflags(e);
            return;
        }
    }
}
Example #2
0
void clock_set_time(struct CLOCK *clock, unsigned int time_out)
{
	int e;
	struct CLOCK *c, *s;
	clock->time_out = time_out + clock_ctl->count;
	clock->flag_usage = CLOCK_FLAGS_USING;
	e = io_load_eflags();
	io_cli();
	c = clock_ctl->c0;
	if (clock->time_out <= c->time_out) {
		clock_ctl->c0 = clock;
		clock->next = c;
		clock_ctl->next = clock->time_out;
		io_store_eflags(e);
		return;
	}
	for (;;) {
		s = c;
		c = c->next;
		if (clock->time_out <= c->time_out) {
			s->next = clock;
			clock->next = c;
			io_store_eflags(e);
			return;
		}
	}
}
Example #3
0
void timer_settime(struct TIMER *timer, unsigned int timeout)
{
	/*
	* timeout: 0.01s
	*/
	int e;
	struct TIMER *t, *s;
	timer->timeout = timeout + timerctl.count;
	timer->flags = TIMER_FLAGS_USING;
	e = io_load_eflags();
	io_cli();
	t = timerctl.t0;
	if (timer->timeout <= t->timeout) {
		/* 插入最前面的情况下 */
		timerctl.t0 = timer;
		timer->nextTimer = t;									/* 下面是t */
		timerctl.nextTime = timer->timeout;
		io_store_eflags(e);
		return;
	}
	/* 搜寻插入位置 */
	for (;;) {
		s = t;
		t = t->nextTimer;
		if (timer->timeout <= t->timeout) {
			/* 插入到s和t之间时 */
			s->nextTimer = timer;								/* s的下一个是timer */
			timer->nextTimer = t;								/* timer的下一个是t */
			io_store_eflags(e);
			return;
		}
	}
}
Example #4
0
void timer_settime(struct TIMER *timer, unsigned int timeout)
{
	int e; 
	struct TIMER *t, *s;
	timer->timeout = timeout + timerctl.count;
	timer->flags = TIMER_FLAGS_USING;
	e = io_load_eflags();
	io_cli();
	/*t = timerctl.t0;
	if (1==timerctl.using){
		timerctl.t0 = timer;
		timer->next = 0;
		timerctl.next = timer->timeout;
		io_store_eflags(e);
		return;
	}*/
	t = timerctl.t0;
	if (timer->timeout<=t->timeout){
		timerctl.t0 = timer;
		timer->next = t;
		timerctl.next = timer->timeout;
		io_store_eflags(e);
		return;
	}
	for (;;){
		s = t;
		t = t->next;
		if (timer->timeout<=t->timeout){
			s->next = timer;
			timer->next = t;
			io_store_eflags(e);
			return;
		}
	}
}
Example #5
0
int timer_cancel(struct TIMER *timer)
{
	int e;
	struct TIMER *t;
	e = io_load_eflags();
	io_cli();	/* 在设置过程中禁止改变定时器状态 */
	if (timer->flags == TIMER_FLAGS_USING) {	/* 是否要取消? */
		if (timer == timerctl.t0) {
			/* 第一个定时器的取消处理 */
			t = timer->next;
			timerctl.t0 = t;
			timerctl.next = t->timeout;
		} else {
			/* 非第一个定时器的取消处理 */
			/* 找到timer前一个定时器 */
			t = timerctl.t0;
			for (;;) {
				if (t->next == timer) {
					break;
				}
				t = t->next;
			}
			t->next = timer->next; /* 将之前“timer的下一个”指向“timer的下一个” */
		}
		timer->flags = TIMER_FLAGS_ALLOC;
		io_store_eflags(e);
		return 1;	/* 取消处理成功 */
	}
	io_store_eflags(e);
	return 0; /* 不需要取消处理 */
}
Example #6
0
File: memory.c Project: 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;
}
Example #7
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;
}
Example #8
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;
}
Example #9
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;
}
Example #10
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;
}
Example #11
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;
}
Example #12
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;
}
Example #13
0
void timer_settimer ( struct TIMER *timer, unsigned int timeout )
{
	int e;
	struct TIMER *t, *s;
	timer->timeout = timeout + timerctl.count;
	timer->flags = TIMER_FLAGS_USING;
	e = io_load_eflags();
	io_cli();
//	timerctl.using ++;

	t = timerctl.t0;
	if ( timer->timeout <= t->timeout ) {
	/* Inserting to the fisrt place*/
		timerctl.t0 = timer;
		timer->next = t;
		timerctl.next = timer->timeout;
		io_store_eflags(e);
		return ;
	}
	while (1) {
		s = t;
		t = t->next;
		if ( timer->timeout <= t->timeout ) {
		/*between t and s */
			s->next = timer;
			timer->next = t;
			io_store_eflags(e);
			return ;
		}
	}
	return ;	
}
Example #14
0
int timer_cancel (struct TIMER *timer)
{
    int e;
    struct TIMER *t;
    e = io_load_eflags();
    io_cli();
    if (timer->flags == TIMER_FLAGS_USING) {
        if (timer == timerctl.t0) {
            t = timer->next;

            timerctl.t0 = t;
            timerctl.next = t->timeout;
        } else {
            t = timerctl.t0;
            for (;;) {
                if (t->next == timer) break;
                t = t->next;
            }
            t->next = timer->next;
        }
        timer->flags = TIMER_FLAGS_ALLOC;
        io_store_eflags(e);
        return 1;
    }
    io_store_eflags(e);
    return 0;
}
Example #15
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;
}
Example #16
0
void timer_set(struct TIMER * timer,unsigned int timeout,struct FIFO *fifo,int data)
{
int e;
struct TIMER *s,*t;
timer->timeout = timerctl.count + timeout;  // compare with count
timer->flag = TIMER_FLAG_USING;
timer->fifo = fifo;
timer->data = data;
e = io_load_eflags();
io_cli();
t = timerctl.t0;
if(timeout <= t->timeout)
{
timerctl.t0 = timer;
timer->next = t;  
timerctl.next = timeout;
io_store_eflags(e);
return;
}

for(;;)
{
	s = t;  // s:p t:p+1
 	t = t->next;
	if(timeout <= t->timeout)
	{
	s->next = timer;
	timer->next = t;
	io_store_eflags(e);
	return;
	}
}

}
Example #17
0
int timer_cancel(timer_t* timer)
{
    int e;
    timer_t* t;
    e = io_load_eflags();
    io_cli(); /* 在设置过程中禁止改变定时器状态 */
    if (timer->flags == TIMER_FLAGS_USING) { /* 是否需要取消? */
        if (timer == timerctl.t0) {
            /* 第一个定时器的取消 */
            t = timer->next;
            timerctl.t0 = t;
            timerctl.next = t->timeout;
        } else {
            /* 其他定时器的取消 */
            /* 找到前一个定时器 */
            t = timerctl.t0;
            for (;;) {
                if (t->next == timer) {
                    break;
                }
                t = t->next;
            }
            t->next = timer->next; /* 将「timerの直前」的下一个指向「timerの次」 */
        }
        timer->flags = TIMER_FLAGS_ALLOC;
        io_store_eflags(e);
        return 1; /* 取消成功 */
    }
    io_store_eflags(e);
    return 0; /* 不需要取消处理 */
}
Example #18
0
File: timer.c Project: huu12/testOS
void timer_settime(struct TIMER *timer, unsigned int timeout)
{
	int e;
	struct TIMER *t, *s;
	timer->timeout = timeout + timerctl.count;
	timer->flags = TIMER_FLAGS_USING;
	e = io_load_eflags();
	io_cli();
	t = timerctl.t0;
	if (timer->timeout <= t->timeout) {
		/* 先頭に入れる場合 */
		timerctl.t0 = timer;
		timer->next = t; /* 次はt */
		timerctl.next = timer->timeout;
		io_store_eflags(e);
		return;
	}
	/* どこに入れればいいかを探す */
	for (;;) {
		s = t;
		t = t->next;
		if (timer->timeout <= t->timeout) {
			/* sとtの間に入れる場合 */
			s->next = timer; /* sの次はtimer */
			timer->next = t; /* timerの次はt */
			io_store_eflags(e);
			return;
		}
	}
}
Example #19
0
void timer_settime(struct TIMER *timer, unsigned int timeout)
{
	int e;
	struct TIMER *t, *s;
	timer->timeout = timeout + timerctl.count;
	timer->flags = TIMER_FLAGS_USING;
	e = io_load_eflags();
	io_cli();
	t = timerctl.t0;
	if (timer->timeout <= t->timeout) {
	/* 插入最前面的情况 */
		timerctl.t0 = timer;
		timer->next = t; /* 下面是设定t */
		timerctl.next = timer->timeout;
		io_store_eflags(e);
		return;
	}
	for (;;) {
		s = t;
		t = t->next;
		if (timer->timeout <= t->timeout) {
		/* 插入s和t之间的情况 */
			s->next = timer; /* s下一个是timer */
			timer->next = t; /* timer的下一个是t */
			io_store_eflags(e);
			return;
		}
	}
}
Example #20
0
void timer_settime(UI_Timer *timer, uint timeout)
{
	int ef;
	UI_Timer *t, *s;

	timer->timeout = timeout + system.ui.timer.ctrl.count;
	timer->flags = inuse;
	ef = io_load_eflags();
	io_cli();
	t = system.ui.timer.ctrl.timers;
	if(timer->timeout <= t->timeout){
		system.ui.timer.ctrl.timers = timer;
		timer->next_timer = t;
		system.ui.timer.ctrl.next_count = timer->timeout;
		io_store_eflags(ef);
		return;
	}
	for(;;){
		s = t;
		t = t->next_timer;
		if(timer->timeout <= t->timeout){
			s->next_timer = timer;
			timer->next_timer = t;
			io_store_eflags(ef);
			return;				
		}
	}
}
Example #21
0
void timer_settime(struct _timer *timer, unsigned int timeout) {
    int e;
    struct _timer *t, *s;
    /* Register timer in timerctl */
    timer->timeout = timeout + timerctl.count;
    timer->flags = TIMER_FLAGS_USING;
    e = io_load_eflags();
    io_cli();
    /* Find *timer slot */
    t = timerctl.timersHead;
    /* The only one (abandoned) */
    /*
    if (timerctl.using == 1) { 
        timerctl.timersHead = timer;
        timer->next = 0;
        timerctl.nextto = timer->timeout;
        io_store_eflags(e);
        return;
    }
    */
    /* Insert at the beginning */
    if (timer->timeout <= t->timeout) {
        timerctl.timersHead = timer;
        timer->next = t;
        timerctl.nextto = timer->timeout;
        io_store_eflags(e);
        return;
    }
    /* Insert between s and t*/
    while(1) {
        s = t;
        t = t->next;
        if (t == 0) break; /* End of the list */

        if (timer->timeout <= t->timeout) {
            s->next = timer;
            timer->next = t;
            io_store_eflags(e);
            return;
        }
    }
    /* Insert at the end (abandoned) */
    /*
    s->next = timer;
    timer->next = 0;
    io_store_eflags(e);
    return;
    */
}
Example #22
0
void set_palette(int start, int end, unsigned char *rgb){
	int i, eflags;
	eflags = io_load_eflags();
	io_cli();					/* During initalization, the interruption should not take place*/
	/*
	Access pallete:
	Set color:
	1. Cli
	2. Write the color number to 0x03c8, then write to 0x03c9 in RGB order.
	3. If you want to set the color next to the previous, then write to 0x03c9 in RGB order.
	   If you want to set another color, goto step 2.
	4. Sti
	
	Read color:
	Steps are similar, and you just need to read 0x03c9 insted of writing.
	*/
	io_out8(0x03c8, start);
	for (i = start; i <= end; i++) {
		io_out8(0x03c9, rgb[0] / 4);
		io_out8(0x03c9, rgb[1] / 4);
		io_out8(0x03c9, rgb[2] / 4);
		rgb += 3;
	}
	io_store_eflags(eflags);
	return;
}
Example #23
0
void settimer(unsigned int timeout, struct FIFO8 *fifo, unsigned char data)
{
	int eflags;
	eflags = io_load_eflags();
	io_cli();
	timerctl.timeout = timeout;
	timerctl.fifo = fifo;
	timerctl.data = data;
	io_store_eflags(eflags);
	return;
}
Example #24
0
void Timer::settime(unsigned int timeout){

	int e;
	Timer *t,*s;


	this->timeout = timeout+TimerControl::count;	//ここでのタイムアウトは関数を呼ばれてからの時間のことである
	this->flags = TIMER_FLAGS_USING;			//タイマフラグを使用中にする

	//この関数内で割り込みが起こると困るので
	//割り込みを禁止しておく
	e = io_load_eflags();						//フラグを待避
	io_cli();									//割り込みを禁止


	//ここでタイマーの最後には番兵がいるのを考慮して

	t = TimerControl::t0;
	//1.先頭に入れる場合
	if(this->timeout <= t->timeout){
		TimerControl::t0 = this;
		this->next = t;
		TimerControl::next = this->timeout;
		io_store_eflags(e);
		return;
	}

	//2.どこに入れるか探していれる
	while(1){
		s = t;
		t = t->next;
		if(this->timeout <= t->timeout){
			//このとき    s   <=   timer   <=   t  の関係がある
			//sとtの間にtimerを入れる
			s->next = this;
			this->next = t;
			io_store_eflags(e);
			return;
		}
	}
}
Example #25
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;
}
Example #26
0
void timer_cancelall(FIFO* fifo) {
  int e = io_load_eflags();
  io_cli();
  for (int i = 0; i < MAX_TIMER; ++i) {
    TIMER* t = &timerctl.timers0[i];
    if (t->flags != 0 && t->flags2 != 0 && t->fifo == fifo) {
      timer_cancel(t);
      timer_free(t);
    }
  }
  io_store_eflags(e);
}
Example #27
0
void 
timer_settimer(timer_t* timer, unsigned int timeout)
{
  int eflags;
  timer_t* t; /* timers iterator */
  timer_t* s; /* prev-timer before t */

  timer->timeout = timeout + g_timerctl.count;
  timer->flags = TIMER_FLAGS_USING;
  eflags = io_load_eflags();
  io_cli();

  t = g_timerctl.timer0;
  if (timer->timeout <= t->timeout) {
    /* insert into the front */
    g_timerctl.timer0 = timer;
    timer->next = t;
    g_timerctl.next = timer->timeout;
    io_store_eflags(eflags);
    
    return;
  }

  /* search position to be inserted */
  for ( ; ; ) {
    s = t;
    t = t->next;
    
    if (timer->timeout <= t->timeout) {
      /* insert into between s and t */
      s->next = timer;
      timer->next = t;
      io_store_eflags(eflags);

      return;
    }
  }
}
Example #28
0
int timer_cancel(TIMER* timer) {
  int e = io_load_eflags();
  io_cli();
  if (timer->flags == TIMER_FLAGS_RUNNING) {
    if (timer == timerctl.t0) {
      TIMER* t = timer->next_timer;
      timerctl.t0 = t;
      timerctl.next_time = t->timeout;
    } else {
      TIMER* t = timerctl.t0;
      for (;; t = t->next_timer) {
        if (t->next_timer == timer)
          break;
      }
      t->next_timer = timer->next_timer;
    }
    timer->flags = TIMER_FLAGS_ALLOCATED;
    io_store_eflags(e);
    return TRUE;
  }
  io_store_eflags(e);
  return FALSE;
}
Example #29
0
void set_palette(int start, int end, unsigned char *rgb)
{
	int i, eflags;
	eflags = io_load_eflags();
	io_cli();
	io_out8(0x03c8, start);
	for (i = start; i <= end; i++) {
		io_out8(0x03c9, rgb[0] / 4);
		io_out8(0x03c9, rgb[1] / 4);
		io_out8(0x03c9, rgb[2] / 4);
		rgb += 3;
	}
	io_store_eflags(eflags);
}
Example #30
0
void set_palette(int start, int end, unsigned char *rgb){
	int i, eflags;
	eflags = io_load_eflags(); 	// 记录中断许可标识的值
	io_cli();				   	// 将中断许可标识置为0,禁止中断
	io_out8(0x03c8, start);
	for (i = start; i <= end; i++){
		io_out8(0x03c9, rgb[0] / 4);
		io_out8(0x03c9, rgb[1] / 4);
		io_out8(0x03c9, rgb[2] / 4);
		rgb += 3;
	}
	io_store_eflags(eflags);	// 复原中断许可标识
	return;
}