Example #1
0
File: memory.c Project: red13/chos
unsigned int memman_alloc_4k( MEMMAN* man, unsigned int size )
{
    unsigned int ret;
    size = ( size + 0x0fff ) & 0xfffff000;
    ret = memman_alloc( man, size );
    return ret;
}
Example #2
0
unsigned int memman_alloc_4k(struct mem_controller *man, unsigned int size)
{
	unsigned int a;
	size = (size + 0xfff) & 0xfffff000;
	a = memman_alloc(man, size);
	return a;
}
Example #3
0
unsigned int memman_alloc_4k(struct MEMMAN *memman, unsigned int size)
{
    int a;
    size = (size + 0xfff) & 0xfffff000;
    a = memman_alloc(memman, size);
    return a;
}
Example #4
0
unsigned int memman_alloc_4k(struct MEMMAN *man,unsigned int size)
{
	unsigned int a;
	size = (size + 0xfff) & 0xfffff000;		//以4k(0x1000字节)为单位向上取整
	a = memman_alloc(man,size);
	return a;
}
Example #5
0
unsigned int memman_alloc_4k(MEMMAN_t *man, unsigned int size)
{
    unsigned int a;
    size = (size + 0xfff) & 0xfffff000;
    a = memman_alloc(man, size);
    return a;
}
Example #6
0
void init_pit(void)
{
	int i;
	char cw = 0;
	struct CLOCK *c;
	clock_ctl = (struct CLOCK_CTL*)memman_alloc(memman, sizeof(struct CLOCK_CTL));
	io_out8(PIT_CTRL, 0x34);        /*IRQ0 CLOCK interrupt
										AL = 0x34:OUT(0x43, AL);
										AL = low ;OUT(0x40, AL);
										AL = high;OUT(0x40, AL);
										CLK = CRY_FREQ/AX
                                    */
	io_out8(PIT_CNT0, 0x9c);
	io_out8(PIT_CNT0, 0x2e);
	clock_ctl->count = 0;
	for (i = 0; i < MAX_CLOCK; i++) {
		clock_ctl->clock_list[i].flag_usage = CLOCK_FLAGS_FREE;
	}
	c = clock_alloc();
	c->time_out = 0xffffffff;
	c->flag_usage = CLOCK_FLAGS_USING;
	c->next = 0;
	clock_ctl->c0 = c;
	clock_ctl->next = 0xffffffff; 
	cw = io_in8(PIC0_IMR);
	cw = cw & 0xfe;
	io_out8(PIC0_IMR, cw);
	return;
}
Example #7
0
void sysclock_task(void){
	int i, j;
	unsigned char t[7];
	char err, cnt;
	unsigned char *s;
	static unsigned char adr[7] = { 0x00, 0x02, 0x04, 0x07, 0x08, 0x09, 0x32 };
	static unsigned char max[7] = { 0x60, 0x59, 0x23, 0x31, 0x12, 0x99, 0x99 };
	struct CLOCK *clock_rtc;
	int *buf_rtc;
	struct FIFO32 fifo_rtc;
	struct BOOTINFO *binfo = (struct BOOTINFO*) ADR_BOOTINFO;
	buf_rtc = (int *) memman_alloc(memman, 40);
	s = (unsigned char *) memman_alloc(memman, 6);
	fifo32_init(&fifo_rtc, 10, buf_rtc);
	clock_rtc = clock_alloc();
	clock_init(clock_rtc, &fifo_rtc, 1);
	clock_set_time(clock_rtc, 100);

	for (;;) {
		if (fifo32_status(&fifo_rtc) != 0){
			i = fifo32_get(&fifo_rtc);
			if (i == 1) {
				for (cnt = 0; cnt < 3; cnt++) {
					err = 0;
					for (j = 0; j < 7; j++) {
						io_out8(0x70, adr[j]);
						t[j] = io_in8(0x71);
					}
					for (j = 0; j < 7; j++) {
						io_out8(0x70, adr[j]);
						if (t[j] != io_in8(0x71) || (t[j] & 0x0f) > 9 || t[j] > max[j]) {
							err = 1;
						}
					}
					if (err == 0) {
						break;
					}
				}
				sprintf(s, "%02X:%02X\0", t[2], t[1]);
				boxfill8(binfo->vram, binfo->scrnx, COL8_000000, 100, 100, 164, 116);
				putfonts8_asc(binfo->vram, binfo->scrnx, 100,  100, COL8_848400, s);
				clock_set_time(clock_rtc, 100);
			}
		}
	}
}
Example #8
0
void keyboard(void){
	struct BOOTINFO *binfo = (struct BOOTINFO*) ADR_BOOTINFO;
	int *buf_keyboard;
	char *s;
	struct FIFO32 fifo_keyboard;
	buf_keyboard = (int *) memman_alloc(memman, 40);
	s = (char *) memman_alloc(memman, 40);
	fifo32_init(&fifo_keyboard, 10, buf_keyboard);
	init_keyboard(&fifo_keyboard, 0);
	for(;;){
		if(fifo32_status(&fifo_keyboard) != 0){
			sprintf(s, "%X", fifo32_get(&fifo_keyboard));
			boxfill8(binfo->vram, binfo->scrnx, COL8_000000, 10, 10, 26, 26);
			putfonts8_asc(binfo->vram, binfo->scrnx, 10,  10, COL8_848400, s);
		}
	}
}
Example #9
0
void mouse(void){
	struct BOOTINFO *binfo = (struct BOOTINFO*) ADR_BOOTINFO;
	int *buf_mouse;
	char *s;
	struct FIFO32 fifo_mouse;
	struct MOUSE_DEC mdec;
	buf_mouse = (int *) memman_alloc(memman, 40);
	s = (char *) memman_alloc(memman, 40);
	fifo32_init(&fifo_mouse, 10, buf_mouse);
	enable_mouse(&fifo_mouse, 0, &mdec);
	for(;;){
		if(fifo32_status(&fifo_mouse) != 0){
			if(mouse_decode(&mdec, fifo32_get(&fifo_mouse)) == 1){
				sprintf(s, "X:%d Y:%d BTN:%d Phase:%d", mdec.x, mdec.y, mdec.btn, mdec.phase);
				boxfill8(binfo->vram, binfo->scrnx, COL8_FF0000, 16, 64, 220, 80);
				putfonts8_asc(binfo->vram, binfo->scrnx, 16, 64, COL8_C6C6C6, s);
			}
		}
	}
}
Example #10
0
int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int eax)
{
	int ds_base = *((int *) 0xfe8);
	struct TASK *task = task_now();
	struct CONSOLE *cons = (struct CONSOLE *) *((int *) 0x0fec);
	struct SHTCTL *shtctl = (struct SHTCTL *) *((int *) 0x0fe4);
	struct SHEET *sht;
	int *reg = &eax + 1;	/* eaxの次の番地 */
		/* 保存のためのPUSHADを強引に書き換える */
		/* reg[0] : EDI,   reg[1] : ESI,   reg[2] : EBP,   reg[3] : ESP */
		/* reg[4] : EBX,   reg[5] : EDX,   reg[6] : ECX,   reg[7] : EAX */

	if (edx == 1) {
		cons_putchar(cons, eax & 0xff, 1);
	} else if (edx == 2) {
		cons_putstr0(cons, (char *) ebx + ds_base);
	} else if (edx == 3) {
		cons_putstr1(cons, (char *) ebx + ds_base, ecx);
	} else if (edx == 4) {
		return &(task->tss.esp0);
	} else if (edx == 5) {
		sht = sheet_alloc(shtctl);
		sheet_setbuf(sht, (char *) ebx + ds_base, esi, edi, eax);
		make_window8((char *) ebx + ds_base, esi, edi, (char *) ecx + ds_base, 0);
		sheet_slide(sht, 100, 50);
		sheet_updown(sht, 3);	/* 3という高さはtask_aの上 */
		reg[7] = (int) sht;
	} else if (edx == 6) {
		sht = (struct SHEET *) ebx;
		putfonts8_asc(sht->buf, sht->bxsize, esi, edi, eax, (char *) ebp + ds_base);
		sheet_refresh(sht, esi, edi, esi + ecx * 8, edi + 16);
	} else if (edx == 7) {
		sht = (struct SHEET *) ebx;
		boxfill8(sht->buf, sht->bxsize, ebp, eax, ecx, esi, edi);
		sheet_refresh(sht, eax, ecx, esi + 1, edi + 1);
	} else if (edx == 8) {
		memman_init((struct MEMMAN *) (ebx + ds_base));
		ecx &= 0xfffffff0;	/* 16バイト単位に */
		memman_free((struct MEMMAN *) (ebx + ds_base), eax, ecx);
	} else if (edx == 9) {
		ecx = (ecx + 0x0f) & 0xfffffff0; /* 16バイト単位に切り上げ */
		reg[7] = memman_alloc((struct MEMMAN *) (ebx + ds_base), ecx);
	} else if (edx == 10) {
		ecx = (ecx + 0x0f) & 0xfffffff0; /* 16バイト単位に切り上げ */
		memman_free((struct MEMMAN *) (ebx + ds_base), eax, ecx);
	} else if (edx == 11) {
		sht = (struct SHEET *) ebx;
		sht->buf[sht->bxsize * edi + esi] = eax;
		sheet_refresh(sht, esi, edi, esi + 1, edi + 1);
	}
	return 0;
}
Example #11
0
int main(int argc, char *argv[]) {

    struct MEMMAN man;
    memman_init(&man, (unsigned int)mem_buf, sizeof(mem_buf));

    int mem1 = memman_alloc(&man, 1);
    int mem2 = memman_alloc(&man, 2);
    int mem16 = memman_alloc(&man, 16);
    int mem952 = memman_alloc(&man, 952);

    memman_dump(&man);
    memman_free(&man, mem1, 1);
    memman_dump(&man);
    memman_free(&man, mem16, 16);
    memman_dump(&man);
    memman_free(&man, mem952, 952);
    memman_dump(&man);
    memman_free(&man, mem2, 2);
    memman_dump(&man);

    return 0;
}
Example #12
0
void HariMain(){
	int *buf_clock;
	char *s;
	struct FIFO32 fifo_clock;
	struct CLOCK *clock;
	struct TASK *task_keyboard, *task_mouse, *task_rtc;
	int count = 0;

	init_all();
	
	buf_clock = (int *) memman_alloc(memman, 40);
	s = (char *) memman_alloc(memman, 40);
	
	fifo32_init(&fifo_clock, 10, buf_clock);
	clock = clock_alloc();
	clock_init(clock, &fifo_clock, 1);
	clock_set_time(clock, 100);
	

	io_sti();

	task_run(first_task(), 2);

	task_keyboard = task_alloc();
	task_keyboard->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024;
	task_keyboard->tss.eip = (int) &keyboard;
	task_keyboard->tss.es = 1 * 8;
	task_keyboard->tss.cs = 2 * 8;
	task_keyboard->tss.ss = 1 * 8;
	task_keyboard->tss.ds = 1 * 8;
	task_keyboard->tss.fs = 1 * 8;
	task_keyboard->tss.gs = 1 * 8;
	task_run(task_keyboard, 2);

	task_mouse = task_alloc();
	task_mouse->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024;
	task_mouse->tss.eip = (int) &mouse;
	task_mouse->tss.es = 1 * 8;
	task_mouse->tss.cs = 2 * 8;
	task_mouse->tss.ss = 1 * 8;
	task_mouse->tss.ds = 1 * 8;
	task_mouse->tss.fs = 1 * 8;
	task_mouse->tss.gs = 1 * 8;
	task_run(task_mouse, 2);
	
	task_rtc = task_alloc();
	task_rtc->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024;
	task_rtc->tss.eip = (int) &sysclock_task;
	task_rtc->tss.es = 1 * 8;
	task_rtc->tss.cs = 2 * 8;
	task_rtc->tss.ss = 1 * 8;
	task_rtc->tss.ds = 1 * 8;
	task_rtc->tss.fs = 1 * 8;
	task_rtc->tss.gs = 1 * 8;
	task_run(task_rtc, 2);

	for(;;){
		if(fifo32_status(&fifo_clock) != 0){
			panic_i(count += fifo32_get(&fifo_clock));
			clock_set_time(clock, 10);
		}
	}
}
Example #13
0
void bootmain(void)
{






/*进入30os的部分*/
struct boot_info *bootp=(struct boot_info *)ADDR_BOOT;
init_screen((struct boot_info * )bootp);
init_palette();  //color table from 0 to 15
//clear_screen(8);   	//red
//draw_window();
int mx,my;//mouse position
//display mouse logo
char mousepic[16*16];     //mouse logo buffer

//display_mouse(bootp->vram,bootp->xsize,16,16,mx,my,mousepic,16);
cli();

//set gdt idt
init_gdtidt();
//remap irq 0-15
//函数中: irq 1(keyboard)对应设置中断号int0x21,    irq 12(mouse)对应的中断号是int0x2c 要写中断服务程序了。
init_pic();

//设置完了gdt,idt后再enable cpu interrupt才是安全的

unsigned char s[40];		    //sprintf buffer
unsigned char keybuf[32];	    //keyfifo
unsigned char mousebuf[128];	//mousefifo
unsigned char data;		        //temp variable to get fifo data
int count=0;
fifo8_init(&keyfifo ,32,keybuf);//keyfifo是一个global data defined in int.c
fifo8_init(&mousefifo,128,mousebuf);

//enable timer ,keyboard and mouse   //1111 1000 后面的三个0代表 accept interrupt request, irq0=timer interrupt
outb(PIC0_IMR, 0xf8);//1111 1000  irq 1 2打开 因为keyboard是irq 1,irq2 enable 8259B 芯片发生的中断请求                                 // enable pic slave and keyboard interrupt
//enable mouse interrupt 1110 1111  irq 12 打开 mouse是irq 12  所以要把pic 1 pic 2的芯片中断响应位打开。
outb(PIC1_IMR, 0xef);
//初始化 鼠标按键控制电路
init_keyboard();

//enable cpu interrupt




unsigned int memtotal;
//get the total memory
memtotal=memtest(0x400000,0xffffffff);
//mem=mem>>20; //convert to MBytes
//sprintf(s,"memory:%dMbytes",mem);
//puts8((char *)bootp->vram ,bootp->xsize,0,100,0,s);
Memman * memman=(Memman *)0x3c0000;
memman_init(memman);
//memman_free(memman,0x1000,0x9e000);
memman_free(memman,0x400000,memtotal-0x400000);
//memman_free(memman,0x600000,0x400000);
//memman_free(memman,0xb00000,0x400000);
char *desktop=(unsigned char*)memman_alloc(memman,320*200);
printdebug(desktop,0);
//while(1);
char *win_buf=(unsigned char*)memman_alloc_4K(memman,160*65);
TIMERCTL *timerctl=(TIMERCTL *)memman_alloc_4K(memman,sizeof(TIMERCTL));
gtimerctl=timerctl;
init_pit(timerctl);//init timerctl


draw_win_buf(desktop);
make_window8(win_buf,160,68,"timer");
init_mouse(mousepic,99);	//99 means background color


sprintf(s,"memory:%dMB,free:%dMB,%d",memtotal>>20
,memman_avail(memman)>>20,memman->cellnum);
puts8(desktop ,bootp->xsize,0,150,0,s);

SHTCTL *shtctl;
shtctl=shtctl_init(memman,bootp->vram,bootp->xsize,bootp->ysize);

SHEET *sht_back,*sht_mouse,*sht_win;
//allocate a sheet space from shtctl
sht_back=sheet_alloc(shtctl);
sht_mouse=sheet_alloc(shtctl);
sht_win=sheet_alloc(shtctl);

//write something inside the window
//puts8(win_buf ,160,24,28,0,"hello ,easy os");
//puts8(win_buf ,160,24,44,0,"second line");//y=28+16=44

//hoop the buffer with sheet
sheet_setbuf(sht_back,desktop,320,200,-1);
sheet_setbuf(sht_mouse,mousepic,16,16,99);
sheet_setbuf(sht_win,win_buf,160,65,-1);

mx=0;my=0;//set mouse initial position
sheet_move(sht_back,0,0);
sheet_move(sht_mouse,mx,my);
sheet_move(sht_win,80,72);

//set sht_back to layer0 ;set sht_mouse to layer1
sheet_updown(sht_back,0);
sheet_updown(sht_win,1);
sheet_updown(sht_mouse,2);
//refresh a specific rectangle
sheet_refresh(sht_back,0,0,bootp->xsize,bootp->ysize);

struct FIFO8 timerfifo,timerfifo2,timerfifo3;
char timerbuf[8],timerbuf2[8],timerbuf3[8];
TIMER *timer,*timer2,*timer3;

fifo8_init(&timerfifo,8,timerbuf);
fifo8_init(&timerfifo2,8,timerbuf2);
fifo8_init(&timerfifo3,8,timerbuf3);

timer=timer_alloc(timerctl,0);
timer2=timer_alloc(timerctl,1);
timer3=timer_alloc(timerctl,2);

timer_init(timer,&timerfifo,1);
timer_init(timer2,&timerfifo2,1);
timer_init(timer3,&timerfifo3,1);
//while(1);
timer_settime(timer,1000,timerctl);
timer_settime(timer2,100,timerctl);
timer_settime(timer3,30,timerctl);
sti();
struct MOUSE_DEC mdec;
enable_mouse(&mdec);   //这里会产生一个mouse interrupt
while(1)
 {


    sprintf(s,"%d",timerctl->count);
    boxfill8(win_buf,160,8,20,44,140,60);
    puts8(win_buf ,160,20,44,0,s);//y=28+16=44
    sheet_refresh(sht_win,20,28,140,60);
    sti();
   if(fifo8_status(&keyfifo) +
   fifo8_status(&mousefifo)  +
   fifo8_status(&timerfifo)  +
   fifo8_status(&timerfifo2) +
   fifo8_status(&timerfifo3)
    == 0)//no data in keyfifo and mousefifo
    {
    //sti();
    //hlt();//wait for interrupt
   }
   else
   {
      if(fifo8_status(&keyfifo) != 0)
      {
        data=fifo8_read(&keyfifo);
        sti();
      }//end of keyboard decoder
      else if(fifo8_status(&mousefifo) != 0)//we have mouse interrupt data to process
      {
        data=fifo8_read(&mousefifo);
        sti();
        if(mouse_decode(&mdec,data))
        {
              //3个字节都得到了
              switch (mdec.button)
              {
                case 1:s[1]='L';break;
                case 2:s[3]='R';break;
                case 4:s[2]='M';break;
              }
              sprintf(s,"[lmr:%d %d]",mdec.x,mdec.y);
              boxfill8(desktop,320,0,32,16,32+15*8-1,33);//一个黑色的小box
              puts8(desktop,bootp->xsize,32,16,7,s);     //display e0
              sheet_refresh(sht_back,32,16,32+20*8-1,31);
        #define white 7
               //because we use sheet layer ,so we do not need this any more
              //boxfill8(p,320,white,mx,my,mx+15,my+15);//用背景色把鼠标原来的color填充,这样不会看到鼠标移动的path
              mx +=mdec.x;//mx=mx+dx
              my +=mdec.y;//my=my+dy
              if(mx<0)
              {
                mx=0;
              }
              if(my<0)
              {
                my=0;
              }


              if(mx>bootp->xsize-1)
              {
                mx=bootp->xsize-1;
              }

              if(my>bootp->ysize-1)
              {
                my=bootp->ysize-1;
              }
              sprintf(s,"(%d, %d)",mx,my);
              boxfill8(desktop,320,0,0,0,79,15);//坐标的背景色
              puts8(desktop ,bootp->xsize,0,0,7,s);//显示坐标
              sheet_refresh(sht_back,0,0,bootp->xsize,15);
              sheet_move(sht_mouse,mx,my);
        }
      }//end of mouse decoder
      else if(fifo8_status(&timerfifo)!=0)
      {
        data=fifo8_read(&timerfifo);
        sti();
        puts8(desktop ,bootp->xsize,0,64,0,"10[sec]");//显示坐标
        sheet_refresh(sht_back,0,64,bootp->xsize,80);
        //printdebug(99,80);
      }//end of timer
      else if(fifo8_status(&timerfifo2)!=0)
      {
        data=fifo8_read(&timerfifo2);
        sti();
        puts8(desktop ,bootp->xsize,0,80,0,"3[sec]");//显示坐标
        sheet_refresh(sht_back,0,80,bootp->xsize,96);
       // printdebug(16,150);
     // while(1);
      }//end of timer2
      else if(fifo8_status(&timerfifo3)!=0)//cursor blink
      {
        data=fifo8_read(&timerfifo3);
        sti();
        //static unsigned a=0;a++;//因为你没有把里面的数据读走,所以一直会进来
        //printdebug(a,0);
            if(data!=0)
            {
                timer_init(timer3,&timerfifo3,0);
                boxfill8(desktop,bootp->xsize,7,8,96,15,111);

            }
            else
            {
                timer_init(timer3,&timerfifo3,1);
                boxfill8(desktop,bootp->xsize,0,8,96,15,111);

            }
            timer_settime(timer3,50,timerctl);
            sheet_refresh(sht_back,8,96,15,111);
            sheet_refresh(sht_back,250,100,320,108);
      }//end of timer3

   }

 }
}
Example #14
0
int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int eax)
{
	struct TASK *task = task_now();
	int ds_base = task->ds_base;
	struct CONSOLE *cons = task->cons;
	struct SHTCTL *shtctl = (struct SHTCTL *) *((int *) 0x0fe4);
	struct SHEET *sht;
	struct FIFO32 *sys_fifo = (struct FIFO32 *) *((int *) 0x0fec);
	int *reg = &eax + 1; /* 返し値 */
	int i;
	struct FILEINFO *finfo;
	struct FILEHANDLE *fh;
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	unsigned char *p;
	int *memtotal = (int *) *((int *) 0x0fe2);
	struct TASK *task2;
	struct FIFO32 *fifo;
	struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO;
	int bpp = binfo->vmode;
	unsigned short *sp;
	unsigned int   *ip;
	struct PICTURE *pic;

	if (edx == 1) {
		cons_putchar(cons, eax & 0xff, 1);
	} else if (edx == 2) {
		cons_putstr0(cons, (char *) ebx + ds_base);
	} else if (edx == 3) {
		cons_putstr1(cons, (char *) ebx + ds_base, ecx);
	} else if (edx == 4) {
		return &(task->tss.esp0);
	} else if (edx == 5) {
		sht = sheet_alloc(shtctl);
		sht->task = task;
		sht->flags |= 0x10;
		sheet_setbuf(sht, (char *) ebx + ds_base, esi, edi, eax);
		make_window((unsigned int *) ((char *) ebx + ds_base), esi, edi, (char *) ecx + ds_base, 0, 0);
		sht->windowname = (char *) ecx + ds_base;
		sheet_slide(sht, ((shtctl->xsize - esi) / 2) & ~3, (shtctl->ysize - edi) / 2);
		keywin_off(shtctl->sheets[shtctl->top - 2]);
		sheet_updown(sht, shtctl->top - 1);
		keywin_on(sht);
		fifo32_put(sys_fifo, 0x4000);	/* key_win変更要求 */
		reg[7] = (int) sht;
	} else if (edx == 6) {
		sht = (struct SHEET *) (ebx & 0xfffffffe);
		putfonts((unsigned int *) (sht->buf), sht->bxsize, esi, edi, get_color(1, eax), (char *) ebp + ds_base);
		if ((ebx & 1) == 0) {
			sheet_refresh(sht, esi, edi, esi + ecx * 8, edi + 16);
		}
	} else if (edx == 7) {
		sht = (struct SHEET *) (ebx & 0xfffffffe);
		boxfill((unsigned int *) (sht->buf), sht->bxsize, get_color(1, ebp), eax, ecx, esi, edi);
		if ((ebx & 1) == 0) {
			sheet_refresh(sht, eax, ecx, esi + 1, edi + 1);
		}
	} else if (edx == 8) {
		memman_init((struct MEMMAN *) (ebx + ds_base));
		ecx &= 0xfffffff0;	/* 16バイト単位にする */
		memman_free((struct MEMMAN *) (ebx + ds_base), eax, ecx);
	} else if (edx == 9) {
		ecx = (ecx + 0x0f) & 0xfffffff0;	/* 16バイト単位に切り上げ */
		reg[7] = memman_alloc((struct MEMMAN *) (ebx + ds_base), ecx);
	} else if (edx == 10) {
		ecx = (ecx + 0x0f) & 0xfffffff0;	/* 16バイト単位に切り上げ */
		memman_free((struct MEMMAN *) (ebx + ds_base), eax, ecx);
	} else if (edx == 11) {
		sht = (struct SHEET *) (ebx & 0xfffffffe);
		i = get_color(1, eax);
		if (bpp == 8) {
			sht->buf[sht->bxsize * edi + esi] = get_color(bpp, i);
		} else if (bpp == 16) {
			sp = (unsigned short *) (sht->buf);
			sp[sht->bxsize * edi + esi] = get_color(bpp, i);
		} else if (bpp == 24) {
			ip = (unsigned int *) (sht->buf);
			ip[sht->bxsize * edi + esi] = get_color(bpp, i);
		}
		if ((ebx & 1) == 0) {
			sheet_refresh(sht, esi, edi, esi + 1, edi + 1);
		}
	} else if (edx == 12) {
		sht = (struct SHEET *) ebx;
		sheet_refresh(sht, eax, ecx, esi, edi);
	} else if (edx == 13) {
		sht = (struct SHEET *) (ebx & 0xfffffffe);
		hrb_api_linewin(sht, eax, ecx, esi, edi, get_color(1, ebp));
		if ((ebx & 1) == 0) {
			if (eax > esi) {
				i = eax;
				eax = esi;
				esi = i;
			}
			if (ecx > edi) {
				i = ecx;
				ecx = edi;
				edi = i;
			}
			sheet_refresh(sht, eax, ecx, esi + 1, edi + 1);
		}
	} else if (edx == 14) {
		sheet_free((struct SHEET *) ebx);
		keywin_on(shtctl->sheets[shtctl->top - 2]);
	} else if (edx == 15) {
		for (;;) {
			io_cli();
			if (fifo32_status(&task->fifo) == 0) {
				if (eax != 0) {
					/* fifoカラッポ */
					task_sleep(task);	/* 寝て待つ */
				} else {
					io_sti();
					reg[7] = -1;
					return 0;
				}
			}
			i = fifo32_get(&task->fifo);
			io_sti();
			if (i <= 1) {
				/* カーソル用 */
				/* アプリ実行中はカーソルが出ないので、いつも次は表示用の1を注文 */
					timer_init(cons->timer, &task->fifo, 1);
					timer_settime(cons->timer, 50);
			}
			if (i == 2) {
				/* カーソルON */
				cons->curcol = 0xffffff;
			}
			if (i == 3) {
				/* カーソルOFF */
				cons->curcol = -1;
			}
			if (i == 4) {
				timer_cancel(cons->timer);
				io_cli();
				fifo32_put(sys_fifo, cons->sht - shtctl->sheets0 + 2024);	/* 2024〜2279 */
				cons->sht = 0;
				io_sti();
			}
			if (i >= 256) {
				reg[7] = i - 256;
				return 0;
			}
		}
	} else if (edx == 16) {
		reg[7] = (int) timer_alloc();
		((struct TIMER *) reg[7])->flags2 = 1;	/* 自動キャンセル有効 */
	} else if (edx == 17) {
		timer_init((struct TIMER *) ebx, &task->fifo, eax + 256);
	} else if (edx == 18) {
		timer_settime((struct TIMER *) ebx, eax);
	} else if (edx == 19) {
		timer_free((struct TIMER *) ebx);
	} else if (edx == 20) {
		if (eax == 0) {
			/* 音を消す */
			i = io_in8(0x61);
			io_out8(0x61, i & 0x0d);
		} else {
			i = 1193180000 / eax;
			io_out8(0x43, 0xb6);
			io_out8(0x42, i & 0xff);
			io_out8(0x42, i >> 8);
			i = io_in8(0x61);
			io_out8(0x61, (i | 0x03) & 0x0f);
		}
	} else if (edx == 21) {
Example #15
0
/* 创建新节点 */
struct Node * CreateNode(void *data){
	struct Node *node = (struct Node *)memman_alloc(memman,sizeof(struct Node));
	node->data = data;
	node->next = NULL;
	return node;
}
Example #16
0
int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int eax)
{
	struct TASK *task = task_now();
	int ds_base = task->ds_base;
	struct CONSOLE *cons = task->cons;
	struct SHTCTL *shtctl = (struct SHTCTL *) *((int *) 0x0fe4);
	struct SHEET *sht;
	struct FIFO32 *sys_fifo = (struct FIFO32 *) *((int *) 0x0fec);
	int *reg = &eax + 1;	/* eaxの次の番地 */
		/* 保存のためのPUSHADを強引に書き換える */
		/* reg[0] : EDI,   reg[1] : ESI,   reg[2] : EBP,   reg[3] : ESP */
		/* reg[4] : EBX,   reg[5] : EDX,   reg[6] : ECX,   reg[7] : EAX */
	int i;
	struct FILEINFO *finfo;
	struct FILEHANDLE *fh;
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;

	if (edx == 1) {
		cons_putchar(cons, eax & 0xff, 1);
	} else if (edx == 2) {
		cons_putstr0(cons, (char *) ebx + ds_base);
	} else if (edx == 3) {
		cons_putstr1(cons, (char *) ebx + ds_base, ecx);
	} else if (edx == 4) {
		return &(task->tss.esp0);
	} else if (edx == 5) {
		sht = sheet_alloc(shtctl);
		sht->task = task;
		sht->flags |= 0x10;
		sheet_setbuf(sht, (char *) ebx + ds_base, esi, edi, eax);
		make_window8((char *) ebx + ds_base, esi, edi, (char *) ecx + ds_base, 0);
		sheet_slide(sht, ((shtctl->xsize - esi) / 2) & ~3, (shtctl->ysize - edi) / 2);
		sheet_updown(sht, shtctl->top); /* 今のマウスと同じ高さになるように指定: マウスはこの上になる */
		reg[7] = (int) sht;
	} else if (edx == 6) {
		sht = (struct SHEET *) (ebx & 0xfffffffe);
		putfonts8_asc(sht->buf, sht->bxsize, esi, edi, eax, (char *) ebp + ds_base);
		if ((ebx & 1) == 0) {
			sheet_refresh(sht, esi, edi, esi + ecx * 8, edi + 16);
		}
	} else if (edx == 7) {
		sht = (struct SHEET *) (ebx & 0xfffffffe);
		boxfill8(sht->buf, sht->bxsize, ebp, eax, ecx, esi, edi);
		if ((ebx & 1) == 0) {
			sheet_refresh(sht, eax, ecx, esi + 1, edi + 1);
		}
	} else if (edx == 8) {
		memman_init((struct MEMMAN *) (ebx + ds_base));
		ecx &= 0xfffffff0;	/* 16バイト単位に */
		memman_free((struct MEMMAN *) (ebx + ds_base), eax, ecx);
	} else if (edx == 9) {
		ecx = (ecx + 0x0f) & 0xfffffff0; /* 16バイト単位に切り上げ */
		reg[7] = memman_alloc((struct MEMMAN *) (ebx + ds_base), ecx);
	} else if (edx == 10) {
		ecx = (ecx + 0x0f) & 0xfffffff0; /* 16バイト単位に切り上げ */
		memman_free((struct MEMMAN *) (ebx + ds_base), eax, ecx);
	} else if (edx == 11) {
		sht = (struct SHEET *) (ebx & 0xfffffffe);
		sht->buf[sht->bxsize * edi + esi] = eax;
		if ((ebx & 1) == 0) {
			sheet_refresh(sht, esi, edi, esi + 1, edi + 1);
		}
	} else if (edx == 12) {
		sht = (struct SHEET *) ebx;
		sheet_refresh(sht, eax, ecx, esi, edi);
	} else if (edx == 13) {
		sht = (struct SHEET *) (ebx & 0xfffffffe);
		hrb_api_linewin(sht, eax, ecx, esi, edi, ebp);
		if ((ebx & 1) == 0) {
			sheet_refresh(sht, eax, ecx, esi + 1, edi + 1);
		}
	} else if (edx == 14) {
		sheet_free((struct SHEET *) ebx);
	} else if (edx == 15) {
		for (;;) {
			io_cli();
			if (fifo32_status(&task->fifo) == 0) {
				if (eax != 0) {
					task_sleep(task);	/* FIFOが空なので寝て待つ */
				} else {
					io_sti();
					reg[7] = -1;
					return 0;
				}
			}
			i = fifo32_get(&task->fifo);
			io_sti();
			if (i <= 1 && cons->sht != 0) { /* カーソル用タイマ */
				/* アプリ実行中はカーソルが出ないので、いつも次は表示用の1を注文しておく */
				timer_init(cons->timer, &task->fifo, 1); /* 次は1を */
				timer_settime(cons->timer, 50);
			}
			if (i == 2) {	/* カーソルON */
				cons->cur_c = COL8_FFFFFF;
			}
			if (i == 3) {	/* カーソルOFF */
				cons->cur_c = -1;
			}
			if (i == 4) {	/* コンソールだけを閉じる */
				timer_cancel(cons->timer);
				io_cli();
				fifo32_put(sys_fifo, cons->sht - shtctl->sheets0 + 2024);	/* 2024〜2279 */
				cons->sht = 0;
				io_sti();
			}
			if (i >= 256) { /* キーボードデータ(タスクA経由)など */
				reg[7] = i - 256;
				return 0;
			}
		}
	} else if (edx == 16) {
		reg[7] = (int) timer_alloc();
		((struct TIMER *) reg[7])->flags2 = 1;	/* 自動キャンセル有効 */
	} else if (edx == 17) {
		timer_init((struct TIMER *) ebx, &task->fifo, eax + 256);
	} else if (edx == 18) {
		timer_settime((struct TIMER *) ebx, eax);
	} else if (edx == 19) {
		timer_free((struct TIMER *) ebx);
	} else if (edx == 20) {
		if (eax == 0) {
			i = io_in8(0x61);
			io_out8(0x61, i & 0x0d);
		} else {
			i = 1193180000 / eax;
			io_out8(0x43, 0xb6);
			io_out8(0x42, i & 0xff);
			io_out8(0x42, i >> 8);
			i = io_in8(0x61);
			io_out8(0x61, (i | 0x03) & 0x0f);
		}
	} else if (edx == 21) {
Example #17
0
////初始化进程管理器
//返回:内核进程task_a
struct TASK *task_init(struct MEMMAN *memman)
{
	int i,j;
	struct TASK *task, *idle;
	struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;

	taskctl = (struct TASKCTL *) memman_alloc_4k(memman, sizeof (struct TASKCTL));
	//事先将全部的TASK结构的TSS和LDT、文件描述符都设置好
	for (i = 0; i < MAX_TASKS; i++) {
		taskctl->tasks0[i].pid = -1;
		taskctl->tasks0[i].forked = 0;
		strcpy(taskctl->tasks0[i].name,"anony");
		taskctl->tasks0[i].flags = 0; //标志未使用
		taskctl->tasks0[i].sel = (TASK_GDT0 + i) * 8; //设置TSS的seletor, 当进行任务切换的时候,是跳转到这个段上的。
		taskctl->tasks0[i].tss.ldtr = (TASK_GDT0 + MAX_TASKS + i) * 8; //任务号
		set_segmdesc(gdt + TASK_GDT0 + i, 103, (int) &taskctl->tasks0[i].tss, AR_TSS32);  //TSS段 
		set_segmdesc(gdt + TASK_GDT0 + MAX_TASKS + i, 15, (int) taskctl->tasks0[i].ldt, AR_LDT); //LDT段
		//设置任务的文件描述符
		for(j=0; j<NR_FILES; j++){
			taskctl->tasks0[i].filp[j] = 0;
		}
		
		/* TODO: 初始化进程的键盘输入缓冲,这里的内存可能没有被释放*/
		int bufCount = 100;
		int *fifobuf = (int *)memman_alloc(memman,sizeof(int)*bufCount);
		taskctl->tasks0[i].ch_buf.task = &taskctl->tasks0[i];
		fifo32_init(&taskctl->tasks0[i].ch_buf, bufCount, fifobuf, 0);
	}
	for (i = 0; i < MAX_TASKLEVELS; i++) {
		taskctl->level[i].running = 0;
		taskctl->level[i].now = 0;
	}

	task = task_alloc();
	task->flags = 2;	/* 活动中标志 */
	task->priority = 2; /* 0.02秒 */
	task->level = 0;	/* 最高LEVEL */
	task_add(task);
	task_switchsub();	/* LEVEL设置 */
	load_tr(task->sel);
	task_timer = timer_alloc();
	timer_settime(task_timer, task->priority);

	idle = task_alloc();
	idle->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024;
	idle->tss.eip = (int) &task_idle;
	idle->tss.es = 1 * 8;
	idle->tss.cs = 2 * 8;
	idle->tss.ss = 1 * 8;
	idle->tss.ds = 1 * 8;
	idle->tss.fs = 1 * 8;
	idle->tss.gs = 1 * 8;
	strcpy(idle->name,"idle");
	task_run(idle, MAX_TASKLEVELS - 1, 1);
	
	//默认情况下,所有进程的父进程都是idle,包括task_a和idle自己。
	for (i = 0; i < MAX_TASKS; i++) {
		taskctl->tasks0[0].parent_pid = idle->pid;
	}

	return task;
}
Example #18
0
File: fs.c Project: jjhlzn/haribote
void mkfs()
{
	MESSAGE driver_msg;
	int i, j;

	int bits_per_sect = SECTOR_SIZE * 8; /* 8 bits per byte */
	
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	fsbuf = (u8 *)memman_alloc(memman,FSBUF_SIZE);

	/* get the geometry of ROOTDEV */
	struct part_info geo;
	//driver_msg.type		= DEV_IOCTL;
	//driver_msg.DEVICE	= MINOR(ROOT_DEV);
	//driver_msg.REQUEST	= DIOCTL_GET_GEO;
	//driver_msg.BUF		= &geo;
	//driver_msg.PROC_NR	= 0; //TASK_FS
	//hd_ioctl(&driver_msg);
	geo.size = 20097;
	
	debug("dev size: 0x%x sectors", geo.size);

	/************************/
	/*      super block     */
	/************************/
	struct super_block sb;
	sb.magic	  = MAGIC_V1;
	sb.nr_inodes	  = bits_per_sect;  //512 * 8 = 4096个i_node
	sb.nr_inode_sects = sb.nr_inodes * INODE_SIZE / SECTOR_SIZE;  //i_node所占用的扇区数=4096 * 32 / 512 = 32
	sb.nr_sects	  = geo.size; /* partition size in sector, 这个分区总共有多少个扇区 */
	sb.nr_imap_sects  = 1; //inode-map所占用的扇区数
	sb.nr_smap_sects  = sb.nr_sects / bits_per_sect + 1; //secotr-map所占用的扇区数
	sb.n_1st_sect	  = 1 + 1 +   /* boot sector & super block */
						sb.nr_imap_sects + sb.nr_smap_sects + sb.nr_inode_sects; //数据区的第一个扇区编号
	sb.root_inode	  = ROOT_INODE;  //root directory占用的inode编号
	sb.inode_size	  = INODE_SIZE; 
	struct inode x;
	sb.inode_isize_off= (int)&x.i_size - (int)&x; //i_size在i-node结构中的偏移
	sb.inode_start_off= (int)&x.i_start_sect - (int)&x; //start_sect在i-node结构中的偏移
	sb.dir_ent_size	  = DIR_ENTRY_SIZE; //DIR_ENTRY结构的大小
	struct dir_entry de;
	sb.dir_ent_inode_off = (int)&de.inode_nr - (int)&de; //inode_nr在dir_entry中的偏移
	sb.dir_ent_fname_off = (int)&de.name - (int)&de; //name在dir_entry中的偏移

	memset1(fsbuf, 0x90, SECTOR_SIZE);
	memcpy1(fsbuf, &sb,  SUPER_BLOCK_SIZE);
	
	debug("sb.n_1st_sect = %d",sb.n_1st_sect);
	
	/* write the super block */
	WR_SECT(ROOT_DEV, 1);

	/************************/
	/*       inode map      */
	/************************/
	memset1(fsbuf, 0, SECTOR_SIZE);
	for (i = 0; i < (NR_CONSOLES + 2); i++)
		fsbuf[0] |= 1 << i;

	assert(fsbuf[0] == 0x1F);/* 0001 1111 : 
	//			  *    | ||||
	//			  *    | |||`--- bit 0 : reserved
	//			  *    | ||`---- bit 1 : the first inode,
	//			  *    | ||              which indicates `/'
	//			  *    | |`----- bit 2 : /dev_tty0
	//			  *    | `------ bit 3 : /dev_tty1
	//			  *    `-------- bit 4 : /dev_tty2
	//			  */
	WR_SECT(ROOT_DEV, 2);

	/************************/
	/*      secter map      */
	/************************/
	memset1(fsbuf, 0, SECTOR_SIZE);
	int nr_sects = NR_DEFAULT_FILE_SECTS + 1;
	/*             ~~~~~~~~~~~~~~~~~~~|~   |
	 *                                |    `--- bit 0 is reserved
	 *                                `-------- for `/'
	 */
	for (i = 0; i < nr_sects / 8; i++)
		fsbuf[i] = 0xFF;

	for (j = 0; j < nr_sects % 8; j++)
		fsbuf[i] |= (1 << j);

	WR_SECT(ROOT_DEV, 2 + sb.nr_imap_sects);

	/* zeromemory the rest sector-map */
	memset1(fsbuf, 0, SECTOR_SIZE);
	for (i = 1; i < sb.nr_smap_sects; i++)
		WR_SECT(ROOT_DEV, 2 + sb.nr_imap_sects + i);

	/************************/
	/*       inodes         */
	/************************/
	/* inode of `/' */
	memset1(fsbuf, 0, SECTOR_SIZE);
	struct inode * pi = (struct inode*)fsbuf;
	pi->i_mode = I_DIRECTORY;
	pi->i_size = DIR_ENTRY_SIZE * 4; /* 4 files:
					  * `.',
					  * `dev_tty0', `dev_tty1', `dev_tty2',
					  */
	pi->i_start_sect = sb.n_1st_sect;
	pi->i_nr_sects = NR_DEFAULT_FILE_SECTS;
	/* inode of `/dev_tty0~2' */
	for (i = 0; i < NR_CONSOLES; i++) {
		pi = (struct inode*)(fsbuf + (INODE_SIZE * (i + 1)));
		pi->i_mode = I_CHAR_SPECIAL;
		pi->i_size = 0;
		pi->i_start_sect = MAKE_DEV(DEV_CHAR_TTY, i);
		debug("pi->i_start_sect = %d",MAKE_DEV(DEV_CHAR_TTY, i));
		pi->i_nr_sects = 0;
	}
	WR_SECT(ROOT_DEV, 2 + sb.nr_imap_sects + sb.nr_smap_sects);

	/************************/
	/*          `/'         */
	/************************/
	memset1(fsbuf, 0, SECTOR_SIZE);
	struct dir_entry * pde = (struct dir_entry *)fsbuf;

	pde->inode_nr = 1;
	strcpy(pde->name, ".");

	/* dir entries of `/dev_tty0~2' */
	for (i = 0; i < NR_CONSOLES; i++) {
		pde++;
		pde->inode_nr = i + 2; /* dev_tty0's inode_nr is 2 */
		
		sprintf(pde->name, "dev_tty%d", i);
		
		debug("pde->inode_nr = %d",pde->inode_nr);
		debug("pde->name = %s",pde->name);
	}
	WR_SECT(ROOT_DEV, sb.n_1st_sect);
}
Example #19
0
File: console.c Project: barmi/bxos
int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int eax)
{
	struct TASK *task = task_now();
	int ds_base = task->ds_base;
	struct CONSOLE *cons = task->cons;
	struct SHTCTL *shtctl = (struct SHTCTL *) *((int *) 0x0fe4);
	struct SHEET *sht;
	struct FIFO32 *sys_fifo = (struct FIFO32 *) *((int *) 0x0fec);
	int *reg = &eax + 1;	/* eax�� ���� ���� */
		/* ������ ���� PUSHAD�� ������ ���� */
		/* reg[0] : EDI,   reg[1] : ESI,   reg[2] : EBP,   reg[3] : ESP */
		/* reg[4] : EBX,   reg[5] : EDX,   reg[6] : ECX,   reg[7] : EAX */
	int i;
	struct FILEINFO *finfo;
	struct FILEHANDLE *fh;
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;

	if (edx == 1) {
		// api_putchar
		cons_putchar(cons, eax & 0xff, 1);
	} else if (edx == 2) {
		// api_putstr0
		cons_putstr0(cons, (char *) ebx + ds_base);
	} else if (edx == 3) {
		// api_putstr1
		cons_putstr1(cons, (char *) ebx + ds_base, ecx);
	} else if (edx == 4) {
		// api_end
		return &(task->tss.esp0);
	} else if (edx == 5) {
		// api_openwin
		sht = sheet_alloc(shtctl);
		sht->task = task;
		sht->flags |= 0x10;
		sheet_setbuf(sht, (char *) ebx + ds_base, esi, edi, eax);
		make_window8((char *) ebx + ds_base, esi, edi, (char *) ecx + ds_base, 0);
		sheet_slide(sht, ((shtctl->xsize - esi) / 2) & ~3, (shtctl->ysize - edi) / 2);
		sheet_updown(sht, shtctl->top); /* ������ ���콺�� ���� ���̰� �ǵ��� ������ ���콺�� �� ���� �ȴ� */
		reg[7] = (int) sht;
	} else if (edx == 6) {
		// api_putstrwin
		sht = (struct SHEET *) (ebx & 0xfffffffe);
		putfonts8_asc(sht->buf, sht->bxsize, esi, edi, eax, (char *) ebp + ds_base);
		if ((ebx & 1) == 0) {
			sheet_refresh(sht, esi, edi, esi + ecx * 8, edi + 16);
		}
	} else if (edx == 7) {
		// api_boxfilwin
		sht = (struct SHEET *) (ebx & 0xfffffffe);
		boxfill8(sht->buf, sht->bxsize, ebp, eax, ecx, esi, edi);
		if ((ebx & 1) == 0) {
			sheet_refresh(sht, eax, ecx, esi + 1, edi + 1);
		}
	} else if (edx == 8) {
		// api_initmalloc
		memman_init((struct MEMMAN *) (ebx + ds_base));
		ecx &= 0xfffffff0;	/* 16����Ʈ ������ */
		memman_free((struct MEMMAN *) (ebx + ds_base), eax, ecx);
	} else if (edx == 9) {
		// api_malloc
		ecx = (ecx + 0x0f) & 0xfffffff0; /* 16����Ʈ ������ ���� */
		reg[7] = memman_alloc((struct MEMMAN *) (ebx + ds_base), ecx);
	} else if (edx == 10) {
		// api_free
		ecx = (ecx + 0x0f) & 0xfffffff0; /* 16����Ʈ ������ ���� */
		memman_free((struct MEMMAN *) (ebx + ds_base), eax, ecx);
	} else if (edx == 11) {
		// api_point
		sht = (struct SHEET *) (ebx & 0xfffffffe);
		sht->buf[sht->bxsize * edi + esi] = eax;
		if ((ebx & 1) == 0) {
			sheet_refresh(sht, esi, edi, esi + 1, edi + 1);
		}
	} else if (edx == 12) {
		// api_refreshwin
		sht = (struct SHEET *) ebx;
		sheet_refresh(sht, eax, ecx, esi, edi);
	} else if (edx == 13) {
		// api_linewin
		sht = (struct SHEET *) (ebx & 0xfffffffe);
		hrb_api_linewin(sht, eax, ecx, esi, edi, ebp);
		if ((ebx & 1) == 0) {
			if (eax > esi) {
				i = eax;
				eax = esi;
				esi = i;
			}
			if (ecx > edi) {
				i = ecx;
				ecx = edi;
				edi = i;
			}
			sheet_refresh(sht, eax, ecx, esi + 1, edi + 1);
		}
	} else if (edx == 14) {
		// api_closewin
		sheet_free((struct SHEET *) ebx);
	} else if (edx == 15) {
		// api_getkey
		for (;;) {
			io_cli();
			if (fifo32_status(&task->fifo) == 0) {
				if (eax != 0) {
					task_sleep(task);	/* FIFO�� ������Ƿ� ��ٸ��� */
				} else {
					io_sti();
					reg[7] = -1;
					return 0;
				}
			}
			i = fifo32_get(&task->fifo);
			io_sti();
			if (i <= 1 && cons->sht != 0) { /* Ŀ���� Ÿ�̸� */
				/* ���ø����̼� �������� Ŀ���� ������ �ʱ� ������, ǥ�ÿ� 1�� call */
				timer_init(cons->timer, &task->fifo, 1); /* ������ 1�� */
				timer_settime(cons->timer, 50);
			}
			if (i == 2) {	/* Ŀ�� ON */
				cons->cur_c = COL8_FFFFFF;
			}
			if (i == 3) {	/* Ŀ�� OFF */
				cons->cur_c = -1;
			}
			if (i == 4) {	/* �ָܼ��� �ݴ´� */
				timer_cancel(cons->timer);
				io_cli();
				fifo32_put(sys_fifo, cons->sht - shtctl->sheets0 + 2024);	/* 2024~2279 */
				cons->sht = 0;
				io_sti();
			}
			if (i >= 256) { /* Ű���� ������(�½�ũ A����) �� */
				reg[7] = i - 256;
				return 0;
			}
		}
	} else if (edx == 16) {
		// api_alloctimer
		reg[7] = (int) timer_alloc();
		((struct TIMER *) reg[7])->flags2 = 1;	/* �ڵ� ĵ�� ��ȿ */
	} else if (edx == 17) {
		// api_inittimer
		timer_init((struct TIMER *) ebx, &task->fifo, eax + 256);
	} else if (edx == 18) {
		// api_settimer
		timer_settime((struct TIMER *) ebx, eax);
	} else if (edx == 19) {
		// api_freetimer
		timer_free((struct TIMER *) ebx);
	} else if (edx == 20) {
		// api_beep
		if (eax == 0) {
			i = io_in8(0x61);
			io_out8(0x61, i & 0x0d);
		} else {
			i = 1193180000 / eax;
			io_out8(0x43, 0xb6);
			io_out8(0x42, i & 0xff);
			io_out8(0x42, i >> 8);
			i = io_in8(0x61);
			io_out8(0x61, (i | 0x03) & 0x0f);
		}
	} else if (edx == 21) {