Пример #1
0
struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal)
{
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	struct SHEET *sht = sheet_alloc(shtctl);
	unsigned char *buf = (unsigned char *) memman_alloc_4k(memman, 256 * 165);
	struct TASK *task = task_alloc();
	int *cons_fifo = (int *) memman_alloc_4k(memman, 128 * 4);
	sheet_setbuf(sht, buf, 256, 165, -1); /* 透明色なし */
	make_window8(buf, 256, 165, "console", 0);
	make_textbox8(sht, 8, 28, 240, 128, COL8_000000);
	task->cons_stack = memman_alloc_4k(memman, 64 * 1024);
	task->tss.esp = task->cons_stack + 64 * 1024 - 12;
	task->tss.eip = (int) &console_task;
	task->tss.es = 1 * 8;
	task->tss.cs = 2 * 8;
	task->tss.ss = 1 * 8;
	task->tss.ds = 1 * 8;
	task->tss.fs = 1 * 8;
	task->tss.gs = 1 * 8;
	*((int *) (task->tss.esp + 4)) = (int) sht;
	*((int *) (task->tss.esp + 8)) = memtotal;
	task_run(task, 2, 2); /* level=2, priority=2 */
	sht->task = task;
	sht->flags |= 0x20;	/* カーソルあり */
	fifo32_init(&task->fifo, 128, cons_fifo, task);
	return sht;
}
Пример #2
0
/* 图层管理结构初始化函数 */
struct SHTCTL *shtctl_init(struct MEMMAN *memman, unsigned char *vram, int xsize, int ysize)
{
	struct SHTCTL *ctl;
	int i;
	/* 为图层管理结构分配内存 */
	ctl = (struct SHTCTL *) memman_alloc_4k(memman, sizeof (struct SHTCTL));
	if (ctl == 0) /* 如果分配失败 */
	{	
		goto err;
	}
	/* 为map分配内存,注意分配的大小是xsize*ysize对4K向上取整,它可以描绘出整个屏幕的图层信息 */
	ctl->map = (unsigned char *) memman_alloc_4k(memman, xsize * ysize);
	if (ctl->map == 0) /* 如果分配失败 */
	{	
		/* 释放最先分配的SHTCTL结构体的内存 */
		memman_free_4k(memman, (int) ctl, sizeof (struct SHTCTL));
		goto err;
	}
	ctl->vram = vram;		
	ctl->xsize = xsize;
	ctl->ysize = ysize;
	ctl->top = -1; /* 一个图层也没有 */
	for (i = 0; i < MAX_SHEETS; i++) 
	{
		ctl->sheets[i].flags = 0; /* 标记为未使用 */
		ctl->sheets[i].ctl = ctl; /* 记录所属 */
	}
err:
	return ctl;
}
Пример #3
0
struct SHTCTL *shtctl_init(struct MEMMAN *memman, unsigned char *vram, int xsize, int ysize)
{
	struct SHTCTL *ctl;
	int i;
	ctl = (struct SHTCTL *) memman_alloc_4k(memman, sizeof(struct SHTCTL));
	if (ctl == 0) {
		goto err;
	}
	/* map에 의해 추가된 부분 */
	ctl->map = (unsigned char *)memman_alloc_4k(memman, xsize * ysize);
	if (ctl->map == 0) {
		memman_free_4k(memman, (int)ctl, sizeof(struct SHTCTL));
		goto err;
	}

	ctl->vram = vram;
	ctl->xsize = xsize;
	ctl->ysize = ysize;
	ctl->top = -1;	/* 시트가 한 장도 없다. */
	for (i = 0; i < MAX_SHEETS; i++) {
		ctl->sheets0[i].flags = 0;		/* 미사용 마크 */
		ctl->sheets0[i].ctl = ctl;		/* 소속을 기록 */
	}
err:
	return ctl;
}
Пример #4
0
struct SHTCTL *shtctl_init(struct MEMMAN *memman, unsigned char *vram, int xsize, int ysize) {
	struct SHTCTL *ctl;
	int i;
	ctl = (struct SHTCTL *)memman_alloc_4k(memman, sizeof(struct SHTCTL));
	if (ctl == 0) {
		return ctl;
	}
	ctl->map = (unsigned char*)memman_alloc_4k(memman, xsize * ysize);
	if(ctl->map == 0) {
		memman_free_4k(memman, (int) ctl, sizeof (struct SHTCTL));
		return ctl;
	}
	ctl->vram = vram;
	ctl->xsize = xsize;
	ctl->ysize = ysize;
	ctl->top = -1;
	for (i = 0; i < MAX_SHEETS; i++) {
		/* 
			initially, all sheets are initialized by marked as unused 
			and we need to initialize the ctl pointer upfront
		*/
		ctl->sheets0[i].flags = 0;
		ctl->sheets0[i].ctl = ctl;
	}
	return ctl;
}
Пример #5
0
struct SHTCTL *shtctl_init(struct MEMMAN *memman, unsigned char *vram, int xsize, int ysize)
{
	struct SHTCTL *ctl;
	int i;
	ctl = (struct SHTCTL *) memman_alloc_4k(memman, sizeof (struct SHTCTL));
	if (ctl == 0) {
		goto err;
	}
	ctl->map = (unsigned char *)memman_alloc_4k(memman, xsize*ysize);
	if(ctl->map == 0){
		memman_free_4k(memman, (int)ctl, sizeof (struct SHTCTL));
		goto err;
	}
	
	ctl->vram = vram;
	ctl->xsize = xsize;
	ctl->ysize = ysize;
	ctl->top = -1; /* no sheet can be seen */
	for (i = 0; i < MAX_SHEETS; i++) {
		ctl->sheets0[i].flags = 0; /* mark as unused */
		ctl->sheets0[i].ctl = ctl; /* record to whom it belong*/
	}
err:
	return ctl;
}
Пример #6
0
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline)
{
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	struct FILEINFO *finfo;
	struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;
	char name[13], *p, *q;
	struct TASK *task = task_now();
	int i, segsiz, datsiz, esp, dathrb;

	/* コマンドラインからファイル名を生成 */
	for (i = 0; i < 8; i++) {
		if (cmdline[i] <= ' ') {
			break;
		}
		name[i] = cmdline[i];
	}
	name[i] = 0; /* とりあえずファイル名の後ろを0にする */

	/* ファイルを探す */
	finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	if (finfo == 0) {
		/* 見つからなかったので後ろに".HRB"をつけてもう一度探してみる */
		name[i    ] = '.';
		name[i + 1] = 'H';
		name[i + 2] = 'R';
		name[i + 3] = 'B';
		name[i + 4] = 0;
		finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	}

	if (finfo != 0) {
		/* ファイルが見つかった場合 */
		p = (char *) memman_alloc_4k(memman, finfo->size);
		file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
		if (finfo->size >= 36 && strncmp(p + 4, "Hari", 4) == 0 && *p == 0x00) {
			segsiz = *((int *) (p + 0x0000));
			esp    = *((int *) (p + 0x000c));
			datsiz = *((int *) (p + 0x0010));
			dathrb = *((int *) (p + 0x0014));
			q = (char *) memman_alloc_4k(memman, segsiz);
			*((int *) 0xfe8) = (int) q;
			set_segmdesc(gdt + 1003, finfo->size - 1, (int) p, AR_CODE32_ER + 0x60);
			set_segmdesc(gdt + 1004, segsiz - 1,      (int) q, AR_DATA32_RW + 0x60);
			for (i = 0; i < datsiz; i++) {
				q[esp + i] = p[dathrb + i];
			}
			start_app(0x1b, 1003 * 8, esp, 1004 * 8, &(task->tss.esp0));
			memman_free_4k(memman, (int) q, segsiz);
		} else {
			cons_putstr0(cons, ".hrb file format error.\n");
		}
		memman_free_4k(memman, (int) p, finfo->size);
		cons_newline(cons);
		return 1;
	}
	/* ファイルが見つからなかった場合 */
	return 0;
}
Пример #7
0
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline)
{
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	struct FILEINFO *finfo;
	struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;
	char name[18], *p, *q;
	struct TASK *task = task_now();
	int i;

	/* コマンドラインからファイル名を生成 */
	for (i = 0; i < 13; i++) {
		if (cmdline[i] <= ' ') {
			break;
		}
		name[i] = cmdline[i];
	}
	name[i] = 0; /* とりあえずファイル名の後ろを0にする */

	/* ファイルを探す */
	finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	if (finfo == 0 && name[i - 1] != '.') {
		/* 見つからなかったので後ろに".HRB"をつけてもう一度探してみる */
		name[i    ] = '.';
		name[i + 1] = 'H';
		name[i + 2] = 'R';
		name[i + 3] = 'B';
		name[i + 4] = 0;
		finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	}

	if (finfo != 0) {
		/* ファイルが見つかった場合 */
		p = (char *) memman_alloc_4k(memman, finfo->size);
		q = (char *) memman_alloc_4k(memman, 64 * 1024);
		*((int *) 0xfe8) = (int) p;
		file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
		set_segmdesc(gdt + 1003, finfo->size - 1, (int) p, AR_CODE32_ER + 0x60);
		set_segmdesc(gdt + 1004, 64 * 1024 - 1,   (int) q, AR_DATA32_RW + 0x60);
		if (finfo->size >= 8 && strncmp(p + 4, "Hari", 4) == 0) {
			start_app(0x1b, 1003 * 8, 64 * 1024, 1004 * 8, &(task->tss.esp0));
		} else {
			start_app(0, 1003 * 8, 64 * 1024, 1004 * 8, &(task->tss.esp0));
		}
		memman_free_4k(memman, (int) p, finfo->size);
		memman_free_4k(memman, (int) q, 64 * 1024);
		cons_newline(cons);
		return 1;
	}
	/* ファイルが見つからなかった場合 */
	return 0;
}
Пример #8
0
int cmd_app (struct CONSOLE *cons, int *fat, char *cmdline)
{
  struct MEMMAN *memman = (struct MEMMAN *)MEMMAN_ADDR;
  struct FILEINFO *finfo;
  struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *)ADR_GDT;
  char name [18];
  int i;
  struct TASK *task = task_now ();
  
  for (i = 0; i < 13; i++) {
    if (cmdline[i] <= ' ') {
      break;
    }
    name[i] = cmdline[i];
  }
  name[i] = 0;
  finfo = file_search (name, (struct FILEINFO *)(ADR_DISKIMG + 0x002600), 224);
  if (finfo == 0 && name[i-1] != '.') {
    name [i+0]  = '.';
    name [i+1]  = 'H';
    name [i+2]  = 'R';
    name [i+3]  = 'B';
    name [i+4]  = 0;
    finfo = file_search (name, (struct FILEINFO *)(ADR_DISKIMG + 0x002600), 224);
  }

  if (finfo != 0) {
    char *p = (char *)memman_alloc_4k (memman, finfo->size);
	char *q = (char *)memman_alloc_4k (memman, 64 * 1024);
    *((int *) 0xfe8) = (int) p;
    file_loadfile (finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
    set_segmdesc (gdt + 1003, finfo->size - 1, (int) p, AR_CODE32_ER + 0x60);
	set_segmdesc (gdt + 1004, 64 * 1024 - 1,   (int) q, AR_DATA32_RW + 0x60);
    if (finfo->size >= 8 && strncmp (p + 4, "Hari", 4) == 0) {
      p[0] = 0xe8;
      p[1] = 0x16;
      p[2] = 0x00;
      p[3] = 0x00;
      p[4] = 0x00;
      p[5] = 0xcb;
    }
	start_app (0, 1003 * 8, 64 * 1024, 1004 * 8, &(task->tss.esp0));
    memman_free_4k (memman, (int) p, finfo->size);
	memman_free_4k (memman, (int) q, 64 * 1024);
    cons_newline (cons);
    return 1;
  }

  return 0;
}
Пример #9
0
struct TASK *task_init(struct MEMMAN *memman)
{
    int i;
    struct TASK *task;
    struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;
    taskctl = (struct TASKCTL *) memman_alloc_4k(memman, sizeof(struct TASKCTL));
    for (i = 0; i < MAX_TASKS; i++) {
	taskctl->tasks0[i].flags = 0;
	taskctl->tasks0[i].sel = (TASK_GDT0 + i) * 8;
	set_segmdesc(gdt + TASK_GDT0 + i, 103, (int) &taskctl->tasks0[i].tss, AR_TSS32);
    }
    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;
    task->level = 0;
    task_add(task);
    task_switchsub();
    load_tr(task->sel);
    task_timer = timer_alloc();
    timer_settime(task_timer, task->priority);
    return task;
}
Пример #10
0
static int page_net_init()
{
	page_net = (struct Page *) memman_alloc_4k((struct MEMMAN *) MEMMAN_ADDR, PGSIZE);
	memset(page_net, 0, PGSIZE);
	page_index = 0;
	return 0;
}
Пример #11
0
struct _task *task_init(struct _memman *memman) {
    int i;
    struct _task *task;
    struct _segmdes *gdt = (struct _segmdes *) ADR_GDT;
    taskctl = (struct _taskctl *) memman_alloc_4k(memman, sizeof (struct _taskctl));
    taskctl->now_lv = 0;
    taskctl->lv_change = 0;
    for (i = 0; i < MAX_TASKS; i++) {
        /* Register all task slots on segment descriptor table */
        taskctl->tasks0[i].flags = TASK_UNUSED;
        taskctl->tasks0[i].sel = (TASK_GDT0 + i) * 8; /* Setup selector (GDT segment) number */
        set_segmdesc(gdt + TASK_GDT0 + i, 103, (int) &taskctl->tasks0[i].tss, AR_TSS32);
    }
    for (i = 0; i < MAX_TASKLEVELS; i++) {
        taskctl->level[i].running = 0;
        taskctl->level[i].now = 0;
    }
    /* Allocate new task for task_init caller */
    task = task_alloc();
    task->flags = TASK_RUNNING;
    /* Priority and level */
    task->priority = 2; /* Timeslice = 10ms * pri */
    task->level = 0; /* Highest Level */
    /* Add task to level control */
    task_add(task);
    /* Recalebrate Running Level */
    task_switchsub();
    /* Activate Current Task */
    load_tr(task->sel);
    task_timer = timer_alloc();
    timer_settime(task_timer, task->priority);
    return task;
}
Пример #12
0
int* utf8str(const char* s)
{
    int codepoint;
    int size = 0, index = 0, out_index = 0;
    unsigned char *utf8 = (unsigned char*)s;
    unsigned char c;
    
    memman_t* memman = (memman_t*)MEMMAN_ADDR;
    int* unicode = (int*)memman_alloc_4k(memman, (utf8len(s) + 1) * sizeof(int));

    c = utf8[index++];
    while (c) {
        if ((c & 0x80) == 0) {
            codepoint = c;
        } else if ((c & 0xe0) == 0xe0) {
            codepoint = (c & 0x1F) << 12;
            c = utf8[index++];
            codepoint |= (c & 0x3F) << 6;
            c = utf8[index++];
            codepoint |= (c & 0x3F);
        } else {
            codepoint = (c & 0x3F) << 6;
            c = utf8[index++];
            codepoint |= (c & 0x3F);
        }
        c = utf8[index++];
        unicode[out_index++] = codepoint;
    }
    unicode[out_index] = 0;
    return unicode;
}
Пример #13
0
/* 
	init taskctl and allocate the first task to the thread that calls the init method
	we don't need to assign it a fifo
	because all it doesn't is to switch by calling farjmp()
	and doesn't need to put data to any buffer
*/
struct TASK *task_init(struct MEMMAN *memman) {
	int i;
	struct TASK *task, *idle;
	struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;
	taskctl = (struct TASKCTL *)memman_alloc_4k(memman, sizeof(struct TASKCTL));
	for(i = 0; i < MAX_TASKS; i++) {
		taskctl->tasks0[i].sel = (TASK_GDT0 + i) * 8;
		taskctl->tasks0[i].flags = 0;
		set_segmdesc(gdt + TASK_GDT0 + i, 103, (int)&taskctl->tasks0[i].tss, AR_TSS32);
	}

	/* initialize all levels */
	for(i = 0; i < MAX_TASKLEVELS; i++) {
		taskctl->level[i].running = 0;
		taskctl->level[i].now = 0;
	}

	/* after initializaing all tasks in taskctl, 
		we need to alloc the first task and assign it to the thread that calls init */
	task = task_alloc();
	task->flags = 2; /* running */
	task->priority = 2; 
	task->level = 0; /* the first task(for mouse/keyboard/timer interruption) should be in highest level */
	task_add(task);
	task_switchsub(); /* update taskctl->now_lv */
	/* set task register to current task */
	load_tr(task->sel);

	idle = task_alloc();
	idle->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 8;
	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;
	/* 
		the idle task will always be running at lowest level 
		in case there's no when there's no active task to run and OS doesn't know where to jump
	*/
	task_run(idle, MAX_TASKLEVELS - 1, 1);

	task_timer = timer_alloc();
	timer_settime(task_timer, task->priority);
	return task;
}
Пример #14
0
/* 整个多任务系统的初始化初始化 */
struct TASK *task_init(struct MEMMAN *memman)
{
	int i;
	struct TASK *task, *idle;
	struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;

	taskctl = (struct TASKCTL *) memman_alloc_4k(memman, sizeof (struct TASKCTL));
	/* 初始化所有的任务的task结构 */
	for (i = 0; i < MAX_TASKS; i++) {
		taskctl->tasks0[i].flags = 0;
		taskctl->tasks0[i].sel = (TASK_GDT0 + i) * 8;	/* 选择子初始化 */
		/* 描述符初始化 */
		set_segmdesc(gdt + TASK_GDT0 + i, 103, (int) &taskctl->tasks0[i].tss, AR_TSS32);
	}
	/* 初始化所有level结构 */
	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);	/* 修改tr寄存器 */
	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;
	task_run(idle, MAX_TASKLEVELS - 1, 1);

	return task;
}
Пример #15
0
/*
1st
task_init
*/
void task_init(struct MEMMAN *memman, struct SHEET *sht_back)
{
    /* init tss_a */
    task_a_esp		= (int) memman_alloc_4k(memman, 4096);
    memset(&tss_a, 0, sizeof(struct TSS32));
    tss_a.ldtr		= 0;
    tss_a.iomap	= 0x40000000;
#if 0
    tss_a.eip		= (int)&task_a_main;
    tss_a.eflags	= 0x00000202;	/**/
    tss_a.esp		= task_a_esp;
    tss_a.es		= 1 * 8;
    tss_a.cs		= 2 * 8;
    tss_a.ss		= 1 * 8;
    tss_a.ds		= 1 * 8;
    tss_a.fs		= 1 * 8;
    tss_a.gs		= 1 * 8;
#endif

    /* init tss_b */
    task_b_esp		= (int) memman_alloc_4k(memman, 4096) + 4096 - 8;
    memset(&tss_b, 0, sizeof(struct TSS32));
    tss_b.ldtr 	= 0;
    tss_b.iomap	= 0x40000000;

    tss_b.eip		= (int)&task_b_main;
    tss_b.eflags	= 0x00000202;	/**/
    tss_b.esp		= task_b_esp;
    tss_b.es		= 1 * 8;
    tss_b.cs		= 2 * 8;
    tss_b.ss		= 1 * 8;
    tss_b.ds		= 1 * 8;
    tss_b.fs		= 1 * 8;
    tss_b.gs		= 1 * 8;

    load_tr(3 * 8);

    *((int *) (task_b_esp + 4)) = (int) sht_back;

    mt_timer = timer_alloc();
    timer_settime(mt_timer, 200);
    mt_tr = 3 * 8;

}
Пример #16
0
/**
 *	@description	初始化
 *	@param			menman:内存地址
 */
struct TASK *task_init(struct MEMMAN *memman){
	int i;
	struct TASK *task, *idle;
	struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;

	taskctl = (struct TASKCTL *) memman_alloc_4k(memman, sizeof (struct TASKCTL));

	//TODO 初始化所有任务
	for (i = 0; i < MAX_TASKS; i++) {
		taskctl->tasks0[i].flags = 0;
		taskctl->tasks0[i].sel = (TASK_GDT0 + i) * 8;
		set_segmdesc(gdt + TASK_GDT0 + i, 103, (int) &taskctl->tasks0[i].tss, AR_TSS32);
	}

	//TODO 初始化所有优先级层
	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;	//最高级别
	task_add(task);
	task_switchsub();	//切换
	load_tr(task->sel);
	task_timer = timer_alloc();
	timer_settime(task_timer, task->priority);

	//TODO 初始化空闲进程
	idle = task_alloc();
	idle->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024;		//X86的栈是向下增长的,所以需要+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;
	task_run(idle, MAX_TASKLEVELS - 1, 1);

	return task;
}
Пример #17
0
void 
init_logmgr(struct LogBufferMgr *log_mgr)
{
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	log_mgr->buf_count = LOG_BUF_COUNT;
	log_mgr->frees = log_mgr->buf_count;
	log_mgr->nr_free_buf = 0;

	char *buf = (char *)memman_alloc_4k(memman, LOG_ENTRY_SIZE * LOG_BUF_COUNT);
	log_mgr->buf = buf;
}
Пример #18
0
struct TASK *open_constask(struct SHEET *sht, unsigned int memtotal)
{
  struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
  struct TASK *task = task_alloc();
  int *cons_fifo = (int *) memman_alloc_4k(memman, 128 * 4);
  task->cons_stack = memman_alloc_4k(memman, 64 * 1024);
  task->tss.esp = task->cons_stack + 64 * 1024 - 12;
  task->tss.eip = (int) &console_task;
  task->tss.es = 1 * 8;
  task->tss.cs = 2 * 8;
  task->tss.ss = 1 * 8;
  task->tss.ds = 1 * 8;
  task->tss.fs = 1 * 8;
  task->tss.gs = 1 * 8;
  *((int *) (task->tss.esp + 4)) = (int) sht;
  *((int *) (task->tss.esp + 8)) = memtotal;
  task_run(task, 2, 2); /* level=2, priority=2 */
  fifo32_init(&task->fifo, 128, cons_fifo, task);
  return task;
}
Пример #19
0
struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal)
{
  struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
  struct SHEET *sht = sheet_alloc(shtctl);
  unsigned char *buf = (unsigned char *) memman_alloc_4k(memman, 256 * 165);
  sheet_setbuf(sht, buf, 256, 165, -1); /* 透明色なし */
  make_window8(buf, 256, 165, "console", 0);
  make_textbox8(sht, 8, 28, 240, 128, COL8_000000);
  sht->task = open_constask(sht, memtotal);
  sht->flags |= 0x20; /* カーソルあり */
  return sht;
}
Пример #20
0
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline)
{
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	struct FILEINFO *finfo;
	struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;
	char name[18], *p;
	int i;

	/* 根据命令行生成文件名 */
	for (i = 0; i < 13; i++) {
		if (cmdline[i] <= ' ') {
			break;
		}
		name[i] = cmdline[i];
	}
	name[i] = 0;                                                /* 暂且将文件名的后面置位0 */
	
	/* 寻找文件 */
	finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	if (finfo == 0 && name[i - 1] != '.') {
		/* 由于找不到文件,故在文件名后面加上“.hrb”后重新寻找 */
		name[i    ] = '.';
		name[i + 1] = 'F';
		name[i + 2] = 'E';
		name[i + 3] = 'X';
		name[i + 4] = 0;
		finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	}

	if (finfo != 0) {
		/* 找到文件的情况 */
		p = (char *) memman_alloc_4k(memman, finfo->size);
		*((int *) 0xfe8) = (int) p;
		file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
		set_segmdesc(gdt + 1003, finfo->size - 1, (int) p, AR_CODE32_ER); // *.fex成功读入内存之后,将其注册为GDT的1003号。1-2号有dsctbl.c使用,3-1002号由mtask.c使用。
		if (finfo->size >= 8 && strncmp(p + 4, "Hari", 4) == 0) {
			p[0] = 0xe8;
			p[1] = 0x16;
			p[2] = 0x00;
			p[3] = 0x00;
			p[4] = 0x00;
			p[5] = 0xcb;
		}
		farcall(0, 1003 * 8);
		memman_free_4k(memman, (int) p, finfo->size);
		cons_newline(cons);
		return 1;
	}
	/* 没有找到文件的情况 */
	return 0;
}
Пример #21
0
static int page_alloc(struct Page **pp)
{
#if HAVE_PAGE_NET
	struct Page *p;
	if (page_index >= MAX_PAGE_FOR_NET)
		return 1;

	p = &page_net[page_index++];
	p->addr = (physaddr_t) memman_alloc_4k((struct MEMMAN *) MEMMAN_ADDR, PGSIZE);
	p->pp_ref = 0;
	*pp = p;
#endif
	return 0;
}
Пример #22
0
struct SHTCTL *shtctl_init(struct MEMMAN *memman, unsigned char *vram, int xsize, int ysize)
{
	struct SHTCTL *ctl;
	int i;
	ctl = (struct SHTCTL *) memman_alloc_4k(memman, sizeof (struct SHTCTL));
	if (ctl == 0) {
		return 0;												// err:内存分配不成功
	}
	ctl->map = (unsigned char *) memman_alloc_4k(memman, xsize * ysize);
	if (ctl->map == 0) {
		memman_free_4k(memman, (int) ctl, sizeof (struct SHTCTL));
		return 0;												// err:内存分配不成功
	}
	ctl->vram = vram;
	ctl->xsize = xsize;
	ctl->ysize = ysize;
	ctl->top = -1;												/* 一个SHEET都没有 */
	for (i = 0; i < MAX_SHEETS; i++) {
		ctl->sheets0[i].flags = 0;								/* 标记为未使用 */
		ctl->sheets0[i].ctl = ctl;								/* 记录所属 */
	}
	return ctl;
}
Пример #23
0
task_t* task_init(memman_t* memman)
{
    int i;
    task_t *task, *idle;
    segment_descriptor* gdt = (segment_descriptor*)ADR_GDT;
    taskctl = (taskctl_t*)memman_alloc_4k(memman, sizeof(taskctl_t));
    for (i = 0; i < MAX_TASKS; i++) {
        taskctl->tasks0[i].flags = 0;
        taskctl->tasks0[i].sel = (TASK_GDT0 + i) * 8;
        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);
        set_segmdesc(gdt + TASK_GDT0 + MAX_TASKS + i, 15, (int)taskctl->tasks0[i].ldt, AR_LDT);
    }
    task = task_alloc();
    task->flags = 2; /* 活动中标志 */
    task->priority = 2; /* 0.02s */
    task->level = 0; /* 最高等级 */
    task_add(task);
    task_switchsub(); /* 设置等级 */
    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;
    task_run(idle, MAX_TASKLEVELS - 1, 1);

    return task;
}
Пример #24
0
TASK* task_init(MEMMAN* memman) {
  SEGMENT_DESCRIPTOR* gdt = (SEGMENT_DESCRIPTOR*)ADR_GDT;
  taskctl = (TASKCTL*)memman_alloc_4k(memman, sizeof(TASKCTL));
  for (int i = 0; i < MAX_TASKS; ++i) {
    taskctl->tasks0[i].flags = 0;
    taskctl->tasks0[i].sel = (TASK_GDT0 + i) * 8;
    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);
    set_segmdesc(gdt + TASK_GDT0 + MAX_TASKS + i, 15, (int)taskctl->tasks0[i].ldt, AR_LDT);
  }
  for (int i = 0; i < MAX_TASKLEVELS; ++i) {
    taskctl->level[i].running = 0;
    taskctl->level[i].now = 0;
  }

  TASK* task = task_alloc();  // Main task.
  task->flags = RUNNING;
  task->priority = 2;  // 0.02 sec
  task->level = 0;  // Max level.
  task_add(task);
  task_switchsub();
  load_tr(task->sel);
  task_timer = timer_alloc();
  timer_settime(task_timer, task->priority);

  TASK* idle = task_alloc();
  idle->tss.esp = (int)memman_alloc_4k(memman, 256) + 256;
  idle->tss.eip = (int)&task_idle;
  idle->tss.es = idle->tss.ss = idle->tss.ds = idle->tss.fs = idle->tss.gs = 1 * 8;
  idle->tss.cs = 2 * 8;
  task_run(idle, MAX_TASKLEVELS - 1, 1);

  taskctl->task_fpu = NULL;

  return task;
}
Пример #25
0
struct SHTCTL *shtctl_init(struct MEMMAN *memman, unsigned char *vram, int xsize, int ysize)
{
	struct SHTCTL *ctl;
	int i;
	ctl = (struct SHTCTL *)memman_alloc_4k(memman, sizeof(struct SHTCTL));
	if (ctl == 0) {
		goto err;
	}
	ctl->map = (unsigned char *)memman_alloc_4k(memman, xsize * ysize); //虚拟图层
	if (ctl->map == 0) {
		memman_free_4k(memman, (int)ctl, sizeof(struct SHTCTL));
		goto err;
	}
	ctl->vram = vram;
	ctl->xsize = xsize;
	ctl->ysize = ysize;
	ctl->top = -1;
	for (i = 0; i < MAX_SHEETS; i++) {
		ctl->sheets0[i].flags = 0; //标记为未使用
		ctl->sheets0[i].ctl = ctl;
	}
err:
	return ctl;
}
Пример #26
0
struct SHTCTL *shtctl_init(struct MEMMAN *memman, unsigned char *vram, int xsize, int ysize)
{
	struct SHTCTL *ctl;
	int i;
	ctl = (struct SHTCTL *) memman_alloc_4k(memman, sizeof (struct SHTCTL));
	if (ctl == 0) {
		return 0;
	}
	ctl->vram = vram;
	ctl->xsize = xsize;
	ctl->ysize = ysize;
	ctl->top = -1;											/* 一个SHEET没都有 */
	for (i = 0; i < MAX_SHEETS; i++) {
		ctl->sheets0[i].flags = 0;							/* 标记为未使用 */
	}
	return ctl;
}
Пример #27
0
/* 图层管理结构初始化函数 */
struct SHTCTL *shtctl_init(struct MEMMAN *memman, unsigned char *vram, int xsize, int ysize)
{
	struct SHTCTL *ctl;
	int i;
	ctl = (struct SHTCTL *) memman_alloc_4k(memman, sizeof (struct SHTCTL));	/* 分配内存 */
	if (ctl == 0) {					/* 如果内存分配失败 */
		goto err;
	}
	ctl->vram = vram;
	ctl->xsize = xsize;
	ctl->ysize = ysize;
	ctl->top = -1; /* 一个图层都没有 */
	for (i = 0; i < MAX_SHEETS; i++) {
		ctl->sheets0[i].flags = 0; /* 标记为未使用 */
	}
err:
	return ctl;
}
Пример #28
0
struct SHTCTL *shtctl_init(struct MEMMAN *memman, unsigned char *vram, int xsize, int ysize)
{
    struct SHTCTL *ctl;
    int i;
    ctl = (struct SHTCTL *)memman_alloc_4k(memman, sizeof(struct SHTCTL));
    if(ctl !=0)
    {
        ctl->vram = vram;
        ctl->xsize = xsize;
        ctl->ysize = ysize;
        ctl->top = -1; // no layer
        for(i =0;i < MAX_SHEETS; i++)
        {
            ctl->sheets0[i].flags = 0; //not in use
        }
    }
    return ctl;
}
Пример #29
0
struct SHTCTL *shtctl_init(struct MEMMAN *memman, unsigned char *vram, int xsize, int ysize)
{
	struct SHTCTL *ctl;
	int i;
	ctl = (struct SHTCTL *) memman_alloc_4k(memman, sizeof (struct SHTCTL));
	if (ctl == 0) {
		goto err;
	}
	ctl->vram = vram;
	ctl->xsize = xsize;
	ctl->ysize = ysize;
	ctl->top = -1; /* シートは一枚もない */
	for (i = 0; i < MAX_SHEETS; i++) {
		ctl->sheets0[i].flags = 0; /* 未使用マーク */
	}
err:
	return ctl;
}
Пример #30
0
void cmd_type(struct CONSOLE *cons, int *fat, char *cmdline)
{
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	struct FILEINFO *finfo = file_search(cmdline + 5, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	char *p;
	if (finfo != 0) {
		/* ファイルが見つかった場合 */
		p = (char *) memman_alloc_4k(memman, finfo->size);
		file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
		cons_putstr1(cons, p, finfo->size);
		memman_free_4k(memman, (int) p, finfo->size);
	} else {
		/* ファイルが見つからなかった場合 */
		cons_putstr0(cons, "File not found.\n");
	}
	cons_newline(cons);
	return;
}