From b9768c427774ea9bd88404503347f62fd633c51f Mon Sep 17 00:00:00 2001 From: Yourtion Date: Tue, 26 Apr 2016 12:17:22 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=B2=E7=BD=AE=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 17_day/bootpack.c | 2 +- 17_day/mtask.c | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/17_day/bootpack.c b/17_day/bootpack.c index 26592fb..760c123 100644 --- a/17_day/bootpack.c +++ b/17_day/bootpack.c @@ -76,7 +76,7 @@ void HariMain(void) task_b[i]->tss.fs = 1 * 8; task_b[i]->tss.gs = 1 * 8; *((int *) (task_b[i]->tss.esp + 4)) = (int) sht_win_b[i]; - task_run(task_b[i], 2, i + 1); + /* task_run(task_b[i], 2, i + 1); */ } /* sht_win */ diff --git a/17_day/mtask.c b/17_day/mtask.c index 148a59c..7f844c2 100644 --- a/17_day/mtask.c +++ b/17_day/mtask.c @@ -64,13 +64,21 @@ void task_switchsub(void) return; } +void task_idle(void) +{ + for (;;) { + io_hlt(); + } +} + struct TASK *task_init(struct MEMMAN *memman) { int i; - struct TASK *task; + struct TASK *task, *idle; struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT; - taskctl = (struct TASKCTL *) memman_alloc_4k(memman, sizeof (struct TASKCTL)); + + 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; @@ -80,6 +88,7 @@ struct TASK *task_init(struct MEMMAN *memman) taskctl->level[i].running = 0; taskctl->level[i].now = 0; } + task = task_alloc(); task->flags = 2; /*活动中标志*/ task->priority = 2; /* 0.02秒*/ @@ -89,6 +98,18 @@ struct TASK *task_init(struct MEMMAN *memman) 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; }