void _benmain(void) { struct FIFO32 fifo; int keybuf[128]={0}; fifo32_init(&fifo, 128, keybuf); struct TSS32 tss_a = {0}; cons_init(); env_init(); /* keyboard setting */ init_kb(&fifo, 256); tss_a.ldtr = 0; tss_a.iomap = 0x40000000; set_segmdesc(gdt + 0, 103, (int) &tss_a, AR_TSS32); task_init(memman); /* Unfortunate try the switch back to 0*8 (_benmain) with farjmp but not working. * And the reason still unknown. * So that I use another thread_kb_io() to catch the keyboard interrupt. */ load_tr(0 * 8); // record current working task to tss_a task_create((int) &thread_kb_io, memman, "bshell", 1); task_create((int) &thread_events, memman, "events", 0); /* strange issue encountered if run pci_init at the setup_hw() */ puts("pci scan bus\n"); pci_init(); farjmp(0, 4*8); puts("\nSystem Halted \n"); _syshalt(); }
void task_sleep(struct TASK *task) { int i; char ts = 0; if (task->flags == 2) { if (task == taskctl->tasks[taskctl->now]) { ts = 1; } for (i = 0; i < taskctl->running; i++) { if (taskctl->tasks[i] == task) { break; } } taskctl->running--; if (i < taskctl->now) { taskctl->now--; } for (; i < taskctl->running; i++) { taskctl->tasks[i] = taskctl->tasks[i + 1]; } task->flags = 1; if (ts != 0) { if (taskctl->now >= taskctl->running) { taskctl->now = 0; } farjmp(0, taskctl->tasks[taskctl->now]->sel); } } return; }
void task_sleep(struct TASK *task) { int i; char ts = 0; if (task->flags == 2) { /* 指定タスクがもし起きていたら */ if (task == taskctl->tasks[taskctl->now]) { ts = 1; /* 自分自身を寝かせるので、あとでタスクスイッチする */ } /* taskがどこにいるかを探す */ for (i = 0; i < taskctl->running; i++) { if (taskctl->tasks[i] == task) { /* ここにいた */ break; } } taskctl->running--; if (i < taskctl->now) { taskctl->now--; /* ずれるので、これもあわせておく */ } /* ずらし */ for (; i < taskctl->running; i++) { taskctl->tasks[i] = taskctl->tasks[i + 1]; } task->flags = 1; /* 動作していない状態 */ if (ts != 0) { /* タスクスイッチする */ if (taskctl->now >= taskctl->running) { /* nowがおかしな値になっていたら、修正する */ taskctl->now = 0; } farjmp(0, taskctl->tasks[taskctl->now]->sel); } } return; }
void task_b_main (struct SHEET *sht_back) { struct FIFO32 fifo; struct TIMER *timer_ts, *timer_put; int i, fifobuf[128], count = 0; fifo32_init(&fifo, 128, fifobuf); timer_ts = timer_alloc(); timer_init(timer_ts, &fifo, 2); timer_settime(timer_ts, 2); timer_put = timer_alloc(); timer_init(timer_put, &fifo, 1); timer_settime(timer_put, 1); for (;;) { count++; io_cli(); if (fifo32_status(&fifo) == 0) { io_stihlt(); } else { i = fifo32_get(&fifo); io_sti(); if (i == 1) { char s[11]; sprintf (s, "%d", count); putfonts8_asc_sht (sht_back, 0, 144, COL8_FFFFFF, COL8_008484, s, 11); timer_settime (timer_put, 1); } else if (i == 2) { // timeout 5 sec farjmp(0, 3 * 8); timer_settime(timer_ts, 2); } } } }
/* will be directly called by inthandler20 */ void task_switch(void) { struct TASKLEVEL *tl = &taskctl->level[taskctl->now_lv]; struct TASK *new_task, *now_task = tl->tasks[tl->now]; /* why can't we use this?? tl->now = (tl->now + 1) % (tl->running); */ tl->now++; if (tl->now == tl->running) { tl->now = 0; } /* need to make sure we are runnig the curret task, update correct running level */ if(taskctl->lv_change != 0) { task_switchsub(); tl = &taskctl->level[taskctl->now_lv]; } new_task = tl->tasks[tl->now]; /* align time slice to new task now */ timer_settime(task_timer, new_task->priority); /* if it's not the same task jump to the new task */ if(new_task != now_task) { farjmp(0, new_task->sel); } return; }
void task_b_main(void) { struct FIFO32 fifo; struct TIMER *timer_ts; int i, fifobuf[128]; fifo32_init(&fifo, 128, fifobuf); timer_ts = timer_alloc(); timer_init(timer_ts, &fifo, 1); timer_settime(timer_ts, 2); for (;;) { io_cli(); if (fifo32_status(&fifo) == 0) { io_sti(); io_hlt(); } else { i = fifo32_get(&fifo); io_sti(); if (i == 1) { /* タスクスイッチ */ farjmp(0, 3 * 8); timer_settime(timer_ts, 2); } } } }
void _benmain(void) { int i; int c = 0; int keybuf[128]={0}; struct FIFO32 fifo; struct TIMER *timer; fifo32_init(&fifo, 128, keybuf); struct TSS32 tss_a, tss_c; env_init(); /* keyboard setting */ init_kb(&fifo, 256); i=0; timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); tss_a.ldtr = 0; tss_a.iomap = 0x40000000; tss_c.ldtr = 0; tss_c.iomap = 0x40000000; set_segmdesc(gdt + 3, 103, (int) &tss_a, AR_TSS32); task_init(memman); /* Unfortunate try the switch back to 3*8 (_benmain) with farjmp but not working. * And the reason still unknown. * So that I use another thread_kb_io() to catch the keyboard interrupt. */ load_tr(3 * 8); // record current working task to tss_a task_create((int) &thread_kb_io, memman, "bshell"); /* strange issue encountered if run pci_init at the setup_hw() */ puts("pci scan bus\n"); pci_init(); for (;;) { asm_cli(); if (fifo32_status(&fifo) == 0) { asm_stihlt(); // wake while keyboard input // got a interrupt } else { /* scan_code input */ c=fifo32_get(&fifo); asm_sti(); if (c == 1) { farjmp(0, 4*8); } else { puts("disabled boot options.\n"); } } } puts("\nSystem Halted \n"); _syshalt(); }
/* 任务切换函数 */ void mt_taskswitch(void) { if (mt_tr == 3 * 8) { mt_tr = 4 * 8; } else { mt_tr = 3 * 8; } timer_settime(mt_timer, 2); farjmp(0, mt_tr); /* 远跳转 */ return; }
void task_switch(void) { timer_settime(task_timer, 2); if (taskctl->running >= 2) { taskctl->now++; if (taskctl->now == taskctl->running) { taskctl->now = 0; } farjmp(0, taskctl->tasks[taskctl->now]->sel); } return; }
//任务切换 void task_switch(void) { timer_set(task_timer, 2); if(taskctl->running_number >= 2) //只要当前运行中的任务有两个以上,就进行任务切换,否则直接结束 { taskctl->task_now++; if(taskctl->task_now == taskctl->running_number) { taskctl->task_now = 0; } farjmp(0, taskctl->running_tasks[taskctl->task_now]->selector); } return ; }
void task_switch(void) { struct TASK *task; taskctl->now++; if (taskctl->now == taskctl->running) { taskctl->now = 0; } task = taskctl->tasks[taskctl->now]; timer_settime(task_timer, task->priority); if (taskctl->running >= 2) { farjmp(0, task->sel); } return; }
void task_sleep(task_t* task) { task_t* now_task; if (task->flags == 2) { /* 活动中 */ now_task = task_now(); task_remove(task); /* flags变1 */ if (task == now_task) { /* 如果是让自己休眠,则需要切换任务 */ task_switchsub(); now_task = task_now(); /* 设置后获取当前任务值 */ farjmp(0, now_task->sel); } } }
void task_sleep(struct TASK *task) { struct TASK *now_task; if (task->flags == 2) { // if specified task is waken now_task = task_now(); task_remove (task); if (task == now_task) { task_switchsub (); now_task = task_now (); farjmp (0, now_task->sel); } } return; }
void task_sleep(TASK* task) { if (task->flags != RUNNING) return; // TODO: Need to prevent interrupt? TASK* now_task = task_now(); task_remove(task); // This makes the task ALLOCATED (sleep). if (task == now_task) { // Sleep by self => need task switch. task_switchsub(); now_task = task_now(); farjmp(0, now_task->sel); } }
void task_sleep(struct TASK *task) { struct TASK *now_task; if (task->flags == 2) { /* 動作中だったら */ now_task = task_now(); task_remove(task); /* これを実行するとflagsは1になる */ if (task == now_task) { /* 自分自身のスリープだったので、タスクスイッチが必要 */ task_switchsub(); now_task = task_now(); /* 設定後での、「現在のタスク」を教えてもらう */ farjmp(0, now_task->sel); } } return; }
/* 使某任务睡眠 */ void task_sleep(struct TASK *task) { struct TASK *now_task; if (task->flags == 2) { /* 如果处于活动状态 */ now_task = task_now(); /* 获得当前正在运行的任务的task指针 */ task_remove(task); /* 执行词语句的话flag会等于1 */ if (task == now_task) { /* 如果是让自己休眠 则需要任务切换 */ task_switchsub(); now_task = task_now(); /* 在设定后获取新的level中待运行的任务 */ farjmp(0, now_task->sel); /* 切换任务 */ } } return; }
/* remove task from its level */ void task_sleep(struct TASK *task) { struct TASK *current_task; /* if the task is running then we remove it from running buffer and mark it as not running */ if(task->flags == 2) { current_task = task_now(); /*task->flags would become 1 */ task_remove(task); /* if a task is termination it self, need to explicitly jump to the new running task */ if(task == current_task) { task_switchsub(); current_task = task_now(); farjmp(0, current_task->sel); } } return; }
//任务休眠 void task_sleep(TASK *task) { TASK *now_task; if (task->flags == RUNNING) { now_task = task_now(); task_remove(task); //执行这行代码之后只是把task从level中移除了,并且flags变成SLEEP状态,但是task本身并没有被释放 if (task == now_task) { /*如果是自己让自己休眠的情况还需要任务转换*/ level_switch(); now_task = task_now(); farjmp(0, now_task->selector); } } return; }
void Task::sleep(){ Task *now_task; //もし対象のタスクが動いていたら if(this->flags == 2){ now_task = TaskControll::task_now(); TaskControll::task_remove(this); //flags = 1 if(this == now_task){ //自身が現在のタスクでスリープにするとき TaskControll::task_switchsub(); now_task = TaskControll::task_now(); farjmp(0,now_task->sel); } } return; }
/** * @description 休眠任务 * @param task:欲休眠的任务 * @notice 休眠任务自己将会引起任务切换 */ void task_sleep(struct TASK *task){ struct TASK *now_task; //TODO 任务有效性检查 if (task->flags == 2) { now_task = task_now(); task_remove(task); if (task == now_task) { //TODO 当前任务,则立即休眠 task_switchsub(); //TODO 获得跳转的目标任务,以跳转 now_task = task_now(); farjmp(0, now_task->sel); } } return; }
/** * @description 任务调度 */ void task_switch(void){ struct TASKLEVEL *tl = &taskctl->level[taskctl->now_lv]; struct TASK *new_task, *now_task = tl->tasks[tl->now]; tl->now++; if (tl->now == tl->running) { tl->now = 0; } if (taskctl->lv_change != 0) { task_switchsub(); tl = &taskctl->level[taskctl->now_lv]; } new_task = tl->tasks[tl->now]; timer_settime(task_timer, new_task->priority); if (new_task != now_task) { farjmp(0, new_task->sel); } return; }
////将该任务从可裕兴队列中移除,同时设置为参数指定的状态 //参数:task -- 需要操作的任务, task_status -- task被设成这个任务状态 static void _task_change_status(struct TASK *task, enum TASK_STATUS task_status) { struct TASK *now_task; if (task->flags == TASK_STATUS_RUNNING) { /* 如果处于活动状态 */ now_task = task_now(); task_remove(task, task_status); if (task == now_task) { /* 如果是让自己休眠,则需要进行任务切换 */ task_switchsub(); now_task = task_now(); /* 在设定后获取当前任务的值 */ //debug("process[%d,%s] go to sleep, process[%d,%s] is running",task->pid,task->name,now_task->pid,now_task->name); farjmp(0, now_task->sel); } } return; }
void task_sleep(struct _task *task) { struct _task *now_task; if (task->flags == TASK_RUNNING) { /* If current task is running */ now_task = task_now(); /* Set 'task' back to READY state */ task_remove(task); /* Sleep yourself */ if (task == now_task) { /* Recalebrate Level */ task_switchsub(); /* Switch Current Task */ now_task = task_now(); /* JMP */ farjmp(0, now_task->sel); } } return; }
void scheduler() { while(true) { cli(); while(ready.size == 0) { __asm__ volatile( "sti;" "hlt;" ); } CURRENT_TASK = ready.head; CURRENT_TASK->status = RUNNING; ready.head = CURRENT_TASK->next; if(--ready.size == 0) ready.tail = NULL; farjmp(0, CURRENT_TASK->pid << 3); sti(); } }
void task_switch(void) { if (taskctl->now_lv >= MAX_TASKLEVELS) { io_stihlt(); return; } TASKLEVEL* tl = &taskctl->level[taskctl->now_lv]; TASK* now_task = tl->tasks[tl->now++]; if (tl->now >= tl->running) tl->now = 0; if (taskctl->lv_change) { task_switchsub(); tl = &taskctl->level[taskctl->now_lv]; } TASK* new_task = tl->tasks[tl->now]; timer_settime(task_timer, new_task->priority); if (new_task != now_task) farjmp(0, new_task->sel); }
/* 该函数只在void inthandler20(int *esp)时钟中断处理中被调用 */ void task_switch(void) { struct TASKLEVEL *tl = &taskctl->level[taskctl->now_lv]; struct TASK *new_task, *now_task = tl->tasks[tl->now]; tl->now++; if (tl->now == tl->running) { /* 当now出现异常时调整它 */ tl->now = 0; } if (taskctl->lv_change != 0) { /* 是否需要检测level */ task_switchsub(); /* 寻找最上层的level */ tl = &taskctl->level[taskctl->now_lv]; /* 修改tl让它指向最上层的level */ } new_task = tl->tasks[tl->now]; timer_settime(task_timer, new_task->priority); if (new_task != now_task) { farjmp(0, new_task->sel); } return; }
void cmd_hlt(struct CONSOLE *cons, int *fat) { struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct FILEINFO *finfo = file_search("HLT.HRB", (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT; 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)); set_segmdesc(gdt + 1003, finfo->size - 1, (int) p, AR_CODE32_ER); farjmp(0, 1003 * 8); memman_free_4k(memman, (int) p, finfo->size); } else { /* ファイルが見つからなかった場合 */ putfonts8_asc_sht(cons->sht, 8, cons->cur_y, COL8_FFFFFF, COL8_000000, "File not found.", 15); cons_newline(cons); } cons_newline(cons); return; }
void TaskControll::task_switch(void){ TaskLevel *tl = &TaskControll::level[TaskControll::now_lv]; Task *now_task = tl->tasks[tl->now]; Task *new_task; tl->now++; if(tl->now == tl->running){ tl->now = 0; } //タスクレベルの切り替え if(TaskControll::lv_change != 0){ task_switchsub(); tl = &TaskControll::level[TaskControll::now_lv]; } new_task = tl->tasks[tl->now]; TaskControll::timer->settime(new_task->priority); //実際のタスクの切り替え if(new_task != now_task){ farjmp(0,new_task->sel); } return; }
void task_switch(void) { struct _tasklevel *tl = &taskctl->level[taskctl->now_lv]; struct _task *new_task, *now_task = tl->tasks[tl->now]; /* Switch to current level:next task */ tl->now++; /* Reset to beginning when proceed to the end */ if (tl->now == tl->running) { tl->now = 0; } /* If it requires level switching */ if (taskctl->lv_change != 0) { task_switchsub(); tl = &taskctl->level[taskctl->now_lv]; } new_task = tl->tasks[tl->now]; /* Timeslice allocation depends on its priority */ timer_settime(task_timer, new_task->priority); /* Only do JMP when there is different task */ if (new_task != now_task) { farjmp(0, new_task->sel); } return; }
//任务切换,主要是给timer的中断处理程序调用的 void task_switch(void) { TASKLEVEL *tl = &taskctl->task_level[taskctl->lv_now]; TASK *new_task, *now_task = tl->tasks_lv[tl->task_now]; tl->task_now++; //先把任务所在的当前level中的任务调整好 if (tl->task_now == tl->running_number) //如果running_number到最后一个了,就重新回到第一个 { tl->task_now = 0; } if (taskctl->lv_change != 0) //如果需要改变level的情况 { level_switch(); //找出当前的最高级level tl = &taskctl->task_level[taskctl->lv_now]; } //找出要转换到的那个任务,并且设置好timer,然后执行任务跳转 new_task = tl->tasks_lv[tl->task_now]; timer_set(task_timer, new_task->priority); if (new_task != now_task) //如果转换任务之后发现还是当前任务,就不用跳转了 { farjmp(0, new_task->selector); } return; }